Script to insert a line


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Script to insert a line
# 8  
Old 03-19-2014
many thnx alister.....now my problem is different as posted....if I get any help..it would be so great:-)
# 9  
Old 03-19-2014
What have you tried? You should be able to solve this new problem by modifying either awk suggestion.

Also, pay attention to how a moderator edited your original post. Use code tags for code and data.

Regards,
Alister
This User Gave Thanks to alister For This Post:
# 10  
Old 03-19-2014
Sorry for that Alister.I will try to maintain the decorum.
As, you said that Yoda's solution will help. Yes it helps but I cannot copy the exact value of the first column, second column, third column, from the last line to current line.That's the issue.These values should be carried from the previous line and not constant across the file.
Thanks and Best Regards,
Navendra
# 11  
Old 03-19-2014
Indra2011,
Please look at the note I just added to message #6 in this thread. Then hit the edit button for that message and compare your original message with my update. Hopefully that will clarify how to use CODE tags.
# 12  
Old 03-19-2014
Quote:
Originally Posted by Indra2011
Code:
3343 2256 7687 123 44 55
3456 4786 9345 344 55 77
4231 2671 7651 600 88 99
2345 4567 4567 123 44 56
9876 6547 3452 342 45 65
2341 4564 4356 600 76 88

If the line with $4=600 then insert a line with
Code:
4231 2671 7651 900 88 99

it is exact copy of the previous line but the $4 $5 $6 changes

thanks in advance....so sorry for the last submit...This CODE always confuse me…
thanks
Moderator's Comments:
Mod Comment CODE and ICODE tags are easy. Hit the CODE or ICODE button in the tool bar and then type your text between the tags hitting the button created. Or enter your text, highlight that text, and hit the CODE or ICODE button to surround the selected text with the appropriate tags. You seem to be hitting the button and then positioning the cursor after the closing tag before entering the text that should be tagged.
Code:
awk '{print} $4==600 {$4=900; $5=88; $6=99; print}' file

If this is not self-speaking enough, use an explicit if within { }
Code:
awk '{print} {if ($4==600) {$4=900; $5=88; $6=99; print}}' file

# 13  
Old 03-19-2014
Made in Germany --- Your are gem...I have no words to appreciate..Many thanks for all the helps
# 14  
Old 03-19-2014
Quote:
Originally Posted by alister
Note that $1==600 in the awk suggestions is a numerical comparison. This can match strings consisting of characters other than just a six followed by a zero followed by a zero. This may or may not be an issue.
[..]
Hi Alister. It is a numerical comparison only if $1 is numerical, like 600, or 600.0 +600.0, otherwise it is a string comparison.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Solaris

sed insert into line 1 via script

Hi I am trying to run a sed command within a script..unfortunately it wasn't written on Solaris so doesn't work. Can anyone help with the correct coding please? It is: sed -i '1i ROWID;ORDER_ID;JOB_NAME;ORDER_TABLE' ${OUTFILE} (4 Replies)
Discussion started by: Grueben
4 Replies

3. 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

4. Shell Programming and Scripting

sed - How to insert line before the first blank line following a token

Hello. I have a config file (/etc/my_config_file) which may content : # # port for HTTP (descriptions, SOAP, media transfer) traffic port=8200 # network interfaces to serve, comma delimited network_interface=eth0 # set this to the directory you want scanned. # * if have multiple... (6 Replies)
Discussion started by: jcdole
6 Replies

5. Shell Programming and Scripting

Korn Shell script to insert at specific line

Hi, I am trying to put together a Korn Shell script to insert at a specific line. The system we use is SunOS 5.10 I can get the line number by using:- num=`sed -n '/export ENV/=' ./tmp.file` Not getting much headway using the above variable's value to insert - export SYBASE=/opt/sybase15... (5 Replies)
Discussion started by: aj8200
5 Replies

6. UNIX for Dummies Questions & Answers

shell script : log to txt and insert new line everytime

Hi, I have this script, while do ps ax|grep 5060 > log.txt echo " " sleep 1 done } I want to actually put a new line everytime the loop is executed in log.txt , but I do not know how to "embed" the echo " " inside the log.txt. (so to say... (1 Reply)
Discussion started by: peuceul
1 Replies

7. Shell Programming and Scripting

Shell script to parse a line and insert a word

Hi All, I have a file like this, data1,data2,,,data5,data6. i want to write a shell script to replace data3 with "/example/string". which means my data file should look like this . data1,data2,example/string],,data5,data6. Could you guys help me to get a sed command or any other command... (8 Replies)
Discussion started by: girish.raos
8 Replies

8. Shell Programming and Scripting

awk script to compare and insert a line

Hi I want to compare a string at fixed position 10-20 for all the lines starting with 6. if they dont match it should take a copy of a line starting with 1 and insert it before the line starting with 6. How do i this? Please help Eg 1 test 1 765533 7643743 6 yes 3 5363653 373833 7... (9 Replies)
Discussion started by: appsguy616
9 Replies

9. UNIX for Dummies Questions & Answers

Need Script to insert colons in each line of file

I have a file with over 500 MAC addresses. Each address is on a new line. However, the MACs do not have ":" I need a script that will read the file, line by line and insert colons in the addresses and then print the results to a new file. current.txt looks like this 111111111111 222222222222... (4 Replies)
Discussion started by: canopus15
4 Replies

10. UNIX for Dummies Questions & Answers

How to insert new line in the data file using the script

Hi all, I have a test.dat file.In that file i have many lines of data. IN between some lines i want to insert a new line while running the test.ksh. Say for ex: In the dat file i have data like N001 100.00 N001 200.00 N001 300.00 N001 400.00 <== After this line i want to... (2 Replies)
Discussion started by: Sona
2 Replies
Login or Register to Ask a Question