How to insert recursive words in a file on every line

 
Thread Tools Search this Thread
Operating Systems Linux Red Hat How to insert recursive words in a file on every line
# 1  
Old 08-02-2011
How to insert recursive words in a file on every line

Hi Guys,
If someone can help me edit my script using sed or awk that will be great.

I am trying to get a list of folders and their sizes upto 2 levels along with the week number by using following -
(I am currently putting this information in a file and plan to run this script EVERY week)

PHP Code:
du ---max-depth=* | awk '{print $1, $2}' 
I can get the week number using -
PHP Code:
echo "Week $(date +%U)"
Output Week 41 
Now, I need to format it in a way where after running each week (say Monday), it should append the output on each line, so combined output should look something like this -

PHP Code:
Folder;Week 42;Week 43;Week 44;  ...
./
test-folder/2011;13G;15G;275G
./system/2011;128G;150G;180G
... 
Problem is I can arrange the first line output and am not able to append similar data when the script runs the second time. (For e.g, in above, I can't add Week 44, 275G recursively for the entire list of folders)

I was thinking of using a script like following though am not able to make it work.

PHP Code:
while read i
do
a=$(echo $i|awk '{print $2}')
echo $(echo 
$i $a.txt)
done   
If someone can help me do the remaining stuff, that would be really great.

Cheers and thanks in advance,
Andrew

---------- Post updated 08-02-11 at 01:20 PM ---------- Previous update was 08-01-11 at 07:43 PM ----------

Can someone please shade some more information on this since I am still trying to use a combination of awk and sed though I am not able to make it work.
# 2  
Old 08-02-2011
Maybe this example can help.
Code:
% cat MAINFILE
Folder;Week 42;Week 43
./test-folder/2011;13G;15G
./system/2011;128G;150G

% cat CURRENTFILE
Week 44
275G
180G

% paste -d';' MAINFILE CURRENTFILE
Folder;Week 42;Week 43;Week 44
./test-folder/2011;13G;15G;275G
./system/2011;128G;150G;180G

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace particular words in file based on if finds another words in that line

Hi All, I need one help to replace particular words in file based on if finds another words in that file . i.e. my self is peter@king. i am staying at north sydney. we all are peter@king. How to replace peter to sham if it finds @king in any line of that file. Please help me... (8 Replies)
Discussion started by: Rajib Podder
8 Replies

2. UNIX for Beginners Questions & Answers

Insert a line of text on nth line of a file

Hi All, I am using UNix Sun OS sun4u sparc SUNW,SPARC-Enterprise My intention is to insert a line of text after 13th line of every file inside a particular directory. While trying to do it for a single file , i am using sed sed '3 i this is the 4th line' filename sed: command garbled: 3... (5 Replies)
Discussion started by: gotamp
5 Replies

3. Shell Programming and Scripting

Search words in multiple file line by line

Hi All I have to search servers name say like 1000+ "unique names" line by line in child.txt files in another file that is a master file where all server present say "master.txt",if child.txt's server name matches with master files then it print yes else no with server name. (4 Replies)
Discussion started by: netdbaind
4 Replies

4. Shell Programming and Scripting

How to read a text file line by line and insert into a database table?

I have a test file that I want to read and insert only certain lines into the the table based on a filter. 1. Rread the log file 12 Hours back Getdate() -12 Hours 2. Extract the following information on for lines that say "DUMP is complete" A. Date B. Database Name C.... (2 Replies)
Discussion started by: JolietJake
2 Replies

5. UNIX for Dummies Questions & Answers

Vi - insert a tab between words?

I have several lines in a file that I want to replace a space with a tab. For example: 111047 Julie Jones email@email.com 111047 Julie Jones email@email.com I want to replace the space after the word "jones" with a tab. How do I achieve that in Vi? Please assist. Thanks! (5 Replies)
Discussion started by: onlinelearner02
5 Replies

6. Shell Programming and Scripting

Insert a new line before every 5th line in a file

Hi, I need to insert a new line containing the string "QUERY" above every 5 lines. The below piece of code inserts a new line after every 5th line awk '{print $0} !(NR%5) {print "QUERY"}' sed 'n;n;n;n;G;' --> I do not know how to give "QUERY" string here But I need to insert it before... (4 Replies)
Discussion started by: royalibrahim
4 Replies

7. Shell Programming and Scripting

Insert space between two words

Hi, I need to insert space between words on my output in UNIX other than the single space given by the space bar on my keyboard, e.g when are you going. (There should be 4 spaces between each of these words) rather than when are you going Can anyone help me with... (3 Replies)
Discussion started by: divroro12
3 Replies

8. Shell Programming and Scripting

How can i delete some words in every line in a file

Hi, I need help to delete a few words in every line in my file. This is how the file look like: VDC DQ 14900098,,,,157426.06849776753,786693.2919373367 10273032,,,,157525.49445429695,776574.5546672409 VDC DG ,10273033,,3er55,,149565.57096061576,801778.9379555212 AS174 892562,,,,, ... (2 Replies)
Discussion started by: andy_s
2 Replies

9. Shell Programming and Scripting

Insert line into file

Hi, My File 'temp.txt' contents are like this. <Managers> Mng={{FIL|FAVEI.mng|111}|15.000000|17.000000|17.000000| Mng={{FIL|FAPSV.mng|222}|3.000000|0.000000|0.000000|0.000000| Mng={{FIL|FAVIF.mng|333}|8.000000|8.000000|8.000000|8.000000|... (3 Replies)
Discussion started by: vinay123
3 Replies

10. UNIX for Advanced & Expert Users

Insert a line as the first line into a very huge file

Hello, I need to insert a line (like a header) as the first line of a very huge file (about 3 ml rows). I am able to do it with sed, but redirecting the output and creating a new file takes quite some time. I was wondering if there was a more efficient way of doing it? Any help would be... (3 Replies)
Discussion started by: shriek
3 Replies
Login or Register to Ask a Question