![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| sed query | gopsman | Shell Programming and Scripting | 4 | 02-03-2009 02:41 AM |
| & in SQL query | Lindarella | Shell Programming and Scripting | 3 | 10-09-2006 04:43 PM |
| Query In awk | raguramtgr | UNIX for Dummies Questions & Answers | 1 | 08-27-2004 11:00 AM |
| RPM Query | silvaman | UNIX for Advanced & Expert Users | 1 | 08-15-2003 07:56 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
sed query
I have a series of folders /temp/a /temp/b /temp/c
In folders a, b, and c, I have files a1.txt……….a20.txt b1.txt……….b40.txt & c1.txt……….c60.txt Each file has the same data format :- Line 1 AAAAA aaaa Line 2 BBB bbbbbb Line 3 CCCC cccccc Etc etc I need to write a sed script which will go through all the files and reformat the data thus :- Line 1 AAAAA aaaa Line 2 BBB Line 3 X bbbbbb Line 4 CCCC cccccc Etc etc So I need to insert a CR/LF in line 2 position 4, create a new Line 3 with a constant text (X) and the value of what was to the right of the previous Line 2 (bbbbbb) and move the remaining lines one line down. Can anyone help please ? I don't know sed very well, and awk not at all. |
|
||||
|
sed solution
Thanks Anbu23
When I posted yesterday, I simplified my problem, thinking that I could follow your logic, and apply it to my actual problem. In fact, it is line 5 position 32 before which the CR/LF is to be inserted. The new line 6 will contain fixed text from position 1 to 31 inclusive, (X) and position 32 to 34 from line 5 will be dropped down to the same positions on line 6. I tried sed "5 s/\(...\).\(.*\)/\1\\ X \2/" $file > tmp but this still spilt after 3 characters. I tried sed "5 s/\(.............................\).\(.*\)/\1\\ X \2/" $file > tmp but got a syntax error. Hope you can further help. Thanks |
|
||||
|
Previously you told that after first few chars in some line has to be moved to next line with X.But now you are telling that you need initial char and X and remaining char in new line.I am not able to get you.
Can you give me example? |
|
||||
|
sed example
Hi Anbu23
input Ref: 12345678^M Value Date: 28-MAY-2006^M Debit A/c: 54321235 - abcdef^M Customer : 100210547 - abcdef^M Debit Amount: 9999999999.00 USD^M Description: wire to Wxxxxxx^M ^M Exchange Rate: 1.00000^M etc etc should turn into Ref: 12345678^M Value Date: 28-MAY-2006^M Debit A/c: 54321235 - abcdef^M Customer : 100210547 - abcdef^M Debit Amount: 9999999999.00^M xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx USD^M Description: wire to Wxxxxxx^M ^M Exchange Rate: 1.00000^M etc etc cutting & pasting has offset the display above, but my earlier line 5 position 31 is accurate. Please also note that there are lots of records in each file, and all have to be reformatted. Many thanks again I do appreciate your support. |
|
||||
|
try this one
awk '{if (match($0,"USD")){print $1 $2 $3,"\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",$4} print $0}' file > newfile
I hope USD will come only in Debit Amount: field. Regards, cskumar |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|