General :: How To Update A File In Bash
Jan 26, 2011how to update a file that is already exist in bash. so far i haven found any. I'm using parameter as my first start for the existent, copy file to a different directory.
View 5 Replieshow to update a file that is already exist in bash. so far i haven found any. I'm using parameter as my first start for the existent, copy file to a different directory.
View 5 RepliesI have a csv file that has a upc code and a qty (inventory). I need to insert it into my mysql table, but the table has several columns including upc, qty, price, etc. point me in the right direction to getting this done? Hopefully I can have a handy script when I'm done and all I do is run that script. I just want to make sure we don't delete the description, price, etc stuff and only update qty, using the upc code as the identifier so that the right qty get's input into the table.
View 4 Replies View RelatedI create a bash script that writes another bash file. But in the generated bash file I want to write a bash command in the file and not executing it.Here's my bash file:
Code:
#!/bin/bash
cat > ~/generateGridmix2data.sh << END
[code]...
I am supposed to take some small files, and print them to a specific printer, such that the small files are concatenated into one file. The file name has to be included in the file that gets printed.
Should I be looking to concatenate the files into one file with the file names included, and then print them?
something like: -printfunction -printername < file*
If I call a bash script with sudo, for example:
sudo bash script.sh
Do I still have to use sudo inside the script in cases like this:
sudo apt-get update
I am wondering is it possible to echo values like below described? The situation is - there are too many "doc" files named like "PLCI507_01234567.doc", and there is a Form in a text file named "form.txt" looks like below:
I am already able to create files in the same format for each documents but now I want all the information in a single form and the form should be updated with file informations ie. file name, created date, md5sum etc.
The updated form.txt should be like below.
how to retrive every portion separately from following file name? DSA4020_frontcover_20346501_2011-05.doc
I want to retrieve informations as below;
name = DSA4020
type = frontcover
id = 20346501
date = 2011-05
is it possible to do with sed??
I've created a bash file that calls another bash. And I would like to get the pid from the second file launched, to wait for the file to ends. The second bash file launches processes in background. How can I get the PID from the second bash file?
Here's my code:
Code:
#!/bin/bash
echo "FIRST"
./second.sh
PID=$(echo $!)
wait $PID
echo "CONTINUUING FIRST"
How do I compare the timestamp of two files? I tried this but it doesn't work:
file1time=`stat -c %Y fil1.txt`
file2time=`stat -c %Y file2.txt`
[code]....
I printed both the time stamps, in order and it gives me
1273143480
1254144394
./script.sh: line 13: [1273143480: command not found
So basically if comparision is not working, I guess. Or if there is any other nice way than what I am doing, please let me know.
Edit: There was no space in between if, so changing it to this works:
if [ $file1time -gt $file2time ]
What's the difference between using > and >>? How can I use both < and > (redirection operators) in a single command?
View 2 Replies View RelatedI frequently use wget to download tarballs and zip files from the web, then either untar then or gunzip them. I do:
Is there a way for me to automatically pass the zip file to tar or unzip WHILE wget-ting?
In pseudocode: wget google.com/somfile.zip && unzip
I have a file named file.txt with the following contents
Code:
19 man
24 house
44 dyam
90 random
I want to read the file into array and store each line in each index. I've tried using the following code.
Code:
dataarray=($( < file.txt ))
It stores each word in each index rather than each line in each index.
total newb here. call me a script kiddie if you want but here is what i need to do and what i have.
need to:search a hidden log file for a specific string, find what comes after that part, and then output the result to a variable or something that can be used by an application or other script to carry out further actions.
I know that cat can output the file, but how do you store that output in a variable to process:
Code:
CONTENT=cat file.txt
This doesn't seem to work?
In my bash file I have asked to navigate to some subdir, unzip a file and stay there but when I type pwd I can see i'm always back to home dir.Any way to get shell stick to subdir?
View 4 Replies View RelatedI tried following the example from here (http:url]......)Open up publicity.html for reading and writing by anyone.
Before: -rw-r--r-- publicity.html
Command: chmod og=rw publicity.html
After: -rw-rw-rw- publicity.html
Here's my terminal session:
username@ubuntu:/etc$ -rw-r--r-- bash.bashrc
-rw-r--r--: command not found
username@ubuntu:/etc$ chmod og=rw bash.bashrc[code]....
Basically, I am trying to locate and copy the newest .json bookmark backup in my .mozilla/firefox/w987sdg9.default/bookmarkbackups directory.
I tried this
Code:
ls -t ~/.mozilla/firefox/b1ahb1ah.default/bookmarkbackups/ | head -1
which does return the newest file, but only the filename itself. I found readlink, but I haven't gotten that to output a full path which I can then feed to copy. So, it seems to me that find might work well here, and I know how to find based on absolute dates, but not relative.
The script starts first a program I wrote earlier that collects specific data from 3 online csv files and write a summary csv file called /Tribalwars/request.csv . The seperator used is ;
the csv file looks like this but can be any number of rows (but not to many mostly 3 - 5)
Title1;tile2;...;title15;
B1;B2;...;B15
C1;C2;...;C15
D1;D2;...;D15
Now the next part of the script, and that is what I want to change, asks me to manually input some data I have to copy paste from the csv file just created. I mean if i choose to continue to do my calculations for city 2, I need to copy-paste C1 for the first variable 'cityname' , copy-paste c2 for the second variable 'xxx',copy-paste C3 for the third variable 'yyy',copy-paste C15 for the fourth variable 'points'
Then it starts new calculations etc, witch only these variables.
Now could it be possible to make a menu from the csv file with only the according cells on the screen and that I only have to choose a row from the menu?
I have been using linux for a bit of time but would still class myself as a noobie. I dont know excatly what I am looking for but I can best describe it in a sanario. I have started creating bash scripts which are looped indefinetly which checks afor files to process. my problem is, is there any way to check if the file is complete, as if the file is large and is being coppied from a different volume the file may still be copying or if the file is being uploaded by a user over samba/nfs, and if the file is still copying the process will most likely fail.
View 1 Replies View RelatedI have many files with name in order of number. e.g)
u0101.asc
u0102.asc
u0103.asc
[code]...
I am trying to read file using for loop.
for ((date=01; date<=31; date++))
do
echo ${date}
done
but '01' is read(print) as '1' How can I make it read from '1' to '01'?
I have a file (.tmpfile) and inside it is a string which i only know part of, the rest being a random group of characters... I would like to know how to pull the whole string out of the file and into a variable.
View 13 Replies View RelatedSo I want to run command through ssh but also run a if check in bash to see ifa file exist. I know that to run ssh commands you do ssh user@server YOURCOMMANDbut if i need to run an if statements, how would this work??
View 4 Replies View RelatedI need some help recovering from a "slight" screwup. We just moved 3 TB of data from one RAID Array to another. Low lever archive files. This was done with a regular cp (for some reason) and now we have lost all the timestamps on the files, and we urgently need to get the timestamps back on these files.
We are running Ubuntu 9.10 Server and we have mounted the following
1. /mnt/old-raid ##Old raid from the old server
2. /mnt/new-raid ##New raid on the server
I know we can read out the timestamp on the old server using the command stat -c '%Y' <<filname>>
I know we can change the timestamp of the file, using the command touch -d '<<date>>'
To get from the stat -c date to the input date in touch we need to use date -d @<<timestamp>> +'%d %b %Y %R'
So my question is, how can I create a loop that will list all files in a folder, get their timestamp and update the old timestamp with the new?
I know how to redirect the output of a terminal to a file. For example, if I want to list all the files in ~/Documents and output to a file called test.txt, I would do this: ls ~/Documents > test.txt The question is, can I copy the output to test.txt AFTER I have carried out the command? This would mean that I wouldn't have to know in advance whether I want to copy the output to file. I want to do something like this: ls ~/Documents Then this: <bash command for copying standard output to test.txt>
View 2 Replies View RelatedI understand the tilde (~) at the end of a file displayed in bash is a backup file in the Linux file system. Is there a way to keep these hidden when listing the contents of a directory?
View 2 Replies View RelatedDespite the history file is unique (~/.bash_history) I see that the multiple bash processes run on different windows are not all updating that file. I presume that the bash is not taking into account this possibility (multiple bashes on multiple windows) and writes thus the history file in a simple straightforward way. This would mean that a number of history entries are lost. I've tried to find information but had no luck so far.
View 1 Replies View RelatedI have this script in the past for csh: Code: ./a.out |& tee prints.txt which will redirect all printfs in the C program to the prints.txt file and at the same time show them in the console. How do you do this in bash? I have seen this, [URL] but it does not work for my bash and sh shells. It says:
Code: -bash: syntax error near unexpected token `&' and
Code: -sh: syntax error: unexpected "&"
I just installed amanda-backup_client-2.6.0p2-1.rhel4.i386.rpm on my Red Hat Enterprise Linux 4 system. But I don't know who to check if it successfully installed or not. When I try to run amrecover from root, I get:
-bash: /usr/sbin/amrecover: cannot execute binary file
Suppose I have a variable called filename which contains the name of a file but the name does not contain an extension.
View 4 Replies View RelatedCode:
#!/bin/bash
echo 'obase=2;10'|bc
[code]...