Copy & Append text


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copy & Append text
# 1  
Old 05-16-2011
Java Copy & Append text

Hi,

I have a huge text file that contains contents like below.

Code:
echo 2VPMUM1CMP01_2011-05-10_18_CPU_Stats_1.txt
awk -F, '{sub ("%","",$8);sum+=100-$8;if (100-$8>max){max=100-$8}}END{printf "max=%.1f%\navg=%.1f%\n",max,sum/NR}'
echo 2VPMUM1CMP01_2011-05-11_10_CPU_Stats_1.txt
awk -F, '{sub ("%","",$8);sum+=100-$8;if (100-$8>max){max=100-$8}}END{printf "max=%.1f%\navg=%.1f%\n",max,sum/NR}'
echo 2VPMUM1CMP01_2011-05-12_02_CPU_Stats_1.txt
awk -F, '{sub ("%","",$8);sum+=100-$8;if (100-$8>max){max=100-$8}}END{printf "max=%.1f%\navg=%.1f%\n",max,sum/NR}'
echo 2VPMUM1CMP01_2011-05-10_19_CPU_Stats_1.txt
awk -F, '{sub ("%","",$8);sum+=100-$8;if (100-$8>max){max=100-$8}}END{printf "max=%.1f%\navg=%.1f%\n",max,sum/NR}'

I want to copy the filename that is written after the word echo on 1st line & append it at the end of awk line below it.

Thanks,
Sunil
# 2  
Old 05-16-2011
Try:
Code:
awk '{if ((NR %2)== 1){ f = $2;print $0;} else {printf "%s %s\n",$0,f} }'  test.txt

This assumes the alternate occurrance of echo and awk
This User Gave Thanks to kumaran_5555 For This Post:
# 3  
Old 05-16-2011
MySQL This is working.

Quote:
Originally Posted by kumaran_5555
Try:
Code:
awk '{if ((NR %2)== 1){ f = $2;print $0;} else {printf "%s %s\n",$0,f} }'  test.txt

This assumes the alternate occurrance of echo and awk
Thanks a lot. This solution is working fine.

Regards,
Sunil
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to preserve the same text and modify the same text to append?

Hi, I have an issue modifying a file. Below is the content of the file. File name - a.txt SELECT LISTAGG(SCORE), LISTAGG(VB), LISTAGG(SCORE*12 + 3), LISTAGG(DOB) from T_CONCAT ; SELECT LISTAGG(SCORE), LISTAGG(VB), LISTAGG(SCORE*100 + 3), from... (1 Reply)
Discussion started by: Mannu2525
1 Replies

2. UNIX for Dummies Questions & Answers

Copy(append ) the contents of file1 and file2 to file3

Platform : Oracle linux 6.5 I have two log files with the following contents # ls -l total 8 -rw-r--r--. 1 root root 75 Dec 10 20:55 myLogfile1.log -rw-r--r--. 1 root root 51 Dec 10 20:57 myLogfile2.log # # cat myLogfile1.log hello world jaded zombies acted quaintly but kept driving... (9 Replies)
Discussion started by: kraljic
9 Replies

3. Shell Programming and Scripting

Use sed to append text to filenames if text not already present

I have some html with hrefs that contain local links to pdf filenames. These filenames should have standardised names, i.e. there should be a label prior to the ".pdf" filename suffix. There can be many of these links on a single line of text and some may already have the label. For example ... (13 Replies)
Discussion started by: adb
13 Replies

4. UNIX for Dummies Questions & Answers

Copy value and append value to a list

Hi, sorry if this has been asked before but I couldnt find it. Essentially I am trying to find a value next to an xml tag say abcd 12345678 the number 1-8 is the number i need to copy to a file of order numbers in my home directory ~/tn/ordernumbers.txt say for example there are 3 or... (3 Replies)
Discussion started by: rg01
3 Replies

5. UNIX for Dummies Questions & Answers

Copy and append

Ok, Here it goes. I have several file in a directory that I want to copy to another directory and append the date to the end of the file. I do not want to zip the I just need a copy. I would like the script to ask the user before copying each file in the directory to keep from making unneeded... (1 Reply)
Discussion started by: Dougj75
1 Replies

6. Red Hat

copy & replace text

how can i copy a certain word from a text file then use this word to replace in another text file?? i tried to use something like: awk '{print "Hit the",$1,"with your",$2}' /aaa/qqqq.txt > uu.txt but i can't add an argument to point to the second file which i will replace in. please... (8 Replies)
Discussion started by: mos33
8 Replies

7. Shell Programming and Scripting

Append && echo "success" to all commands

I am learning to build from SVN and other tools, with a lot of copying and pasting from forums. I like to append && echo "success" to all commands so that I can see at a glance if things went all right. Is there a way that I can have the bash shell append this to all commands? Thanks! (5 Replies)
Discussion started by: dotancohen
5 Replies

8. UNIX for Dummies Questions & Answers

Find, copy, and append into one file

Hi, I am trying to do something relatively easy, but am having some trouble getting it to work. I have multiple files called "distances.log" in numerous subdirectories and sub-subdirectories within a directory. I would like the contents of each of these "distances.log" files to be appended to a... (2 Replies)
Discussion started by: euspilapteryx
2 Replies

9. Shell Programming and Scripting

Compare & append

I need to write a Shell Script to compare two files & display the result. If the two files are different append them and store them in a new file. How do i proceed...can someone give me a coding ? (3 Replies)
Discussion started by: rohits1991
3 Replies

10. Shell Programming and Scripting

How do I search first&second string & copy all content between them to other file?

Hi All, How do I search first string & second string and copy all content between them from one file to another file? Please help me.. Thanks In Advance. Regards, Pankaj (12 Replies)
Discussion started by: pankajp
12 Replies
Login or Register to Ask a Question