Need awk/sed to format a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need awk/sed to format a file
# 1  
Old 07-28-2011
Need awk/sed to format a file

My content of source file is as below
Code:
scr1 a1
scr2 a2 b2
scr3 a3 b3 c3

I need a awk/sed command (to be used in C shell)to format it to something like below
Code:
scr1 $a1 >file1 
scr2 $a2 $b2 >file2
scr3 $a3 $b3 $c3 >file3


Last edited by animesharma; 07-28-2011 at 08:12 AM.. Reason: forgot to mention language
# 2  
Old 07-28-2011
Code:
perl -pe '$i++;s/ / \$/g;s/$/ >file$i/' file

# 3  
Old 07-28-2011
@bartus,
I am really sorry i forgot to mention "which language". I don't have knowledge of perl, can you give a script in C shell or similar shells
# 4  
Old 07-28-2011
If you have Perl installed on your machine, then this code will work in any shell (including C shell).
# 5  
Old 07-28-2011
Through sed..
Code:
sed 's/ \(..\)/ $\1/g;s/.$/& >file&/g' inputfile

# 6  
Old 07-29-2011
Thanks Smilie
# 7  
Old 07-29-2011
Code:
$ x=0;while read line; do x=$(echo "$x" + 1 | bc); echo "$line > file$x"; done < inputfile
scr1 a1 > file1
scr2 a2 b2 > file2
scr3 a3 b3 c3 > file3


Last edited by itkamaraj; 07-29-2011 at 12:51 AM.. Reason: inputfile
This User Gave Thanks to itkamaraj For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Format the text using sed or awk

I was able to figure out how to format a text. Raw Data: $ cat test Thu Aug 23 15:43:28 UTC 2018, hostname01, 232.02, 3, 0.00 Thu Aug 23 15:43:35 UTC 2018, hostname02, 231.09, 4, 0.31 Thu Aug 23 15:43:37 UTC 2018, hostname03, 241.67, 4, 0.43 (5 Replies)
Discussion started by: kenshinhimura
5 Replies

2. Shell Programming and Scripting

Sed/awk command to convert number occurances into date format and club a set of lines

Hi, I have been stuck in this requirement where my file contains the below format. 20150812170500846959990854-25383-8.0.0 "ABC Report" hp96880 "4952" 20150812170501846959990854-25383-8.0.0 End of run 20150812060132846959990854-20495-8.0.0 "XYZ Report" vg76452 "1006962188"... (6 Replies)
Discussion started by: Chinmaya Kabi
6 Replies

3. Shell Programming and Scripting

Datestamp format 2nd change in csv file (awk or sed)

I have a csv file formatted like this: 2014-08-21 18:06:26,A,B,12345,123,C,1232,26/08/14 18:07and I'm trying to change it to MM/DD/YYYY HH:MM for both occurances. I have got this: awk -F, 'NR <=1 {print;next}{"date +%d/%m/%Y\" \"%H:%m -d\""$1 "\""| getline dte;$1=dte}1' OFS="," test.csvThis... (6 Replies)
Discussion started by: say170
6 Replies

4. Shell Programming and Scripting

Help on Log File format using sed or awk

Hello Gurus, First, i would like to know is there any way to solve my problem. i have a log file like this: INFO - ABCDRequest :: processing started for the record <0> TransactionNo <Txn#1> recordID <recID#1> INFO - ABCDRequest :: processing started for the record <0> TransactionNo... (9 Replies)
Discussion started by: VasuKukkapalli
9 Replies

5. Shell Programming and Scripting

Format a log file using sed

I am looking to extract something like this from the below sample log file. 10.28.76.15 SSLC=Z42 71.19.175.130 10.28.76.15 SSLC=Z42 71.19.175.130 10.28.76.15 SSLC=Z42 71.19.175.130 for that I tried something like below and I have no clue how to extract the IP address marked red in the log... (6 Replies)
Discussion started by: Tuxidow
6 Replies

6. Shell Programming and Scripting

Format log file - SED

Hello, I need help to format a log file...again ; )) Here is what I have : FILE='/OPERATIONNEL/SATURNE/MASTER/SATURNE_MASTER_PRE_R20110119.TAR.GZ ... (5 Replies)
Discussion started by: Aswex
5 Replies

7. Shell Programming and Scripting

Please help me format with AWK or SED

INPUT FILE: 9780743565219 "GODS OF NEWPORT" "JAKES, JOHN" 2006 OUTPUT FILE I NEED to CREATE FROM INPUT FILE: cd /data/audiobooks/9780743565219 ~/Desktop/mp3-to-m4b 9780743565219-GODS OF NEWPORT "GODS OF NEWPORT" "JAKES, JOHN" 2006 n ---------- Post updated at 04:19 PM ----------... (6 Replies)
Discussion started by: glev2005
6 Replies

8. Shell Programming and Scripting

awk or sed to format text file

hi all, i have a text file which looks like the below 01 02 abc Top 40 music Kidz Only! MC 851 MC 852 MC 853 7NOW Arch_Diac xyz2 abc h211 Commacc1 Commacc2 Commacc3 (4 Replies)
Discussion started by: posner
4 Replies

9. UNIX for Advanced & Expert Users

Sed to format data in a file

Hi , i need help with formatting a file i am generating which is to be used in mainframe app so the file length has to be 80 for each rows. The file that m able to generate looks like this (consists of two rows only) E 1006756 1006756 Active T E 0551055 0551055 Active T I... (2 Replies)
Discussion started by: cnilashis
2 Replies

10. Shell Programming and Scripting

AWK CSV to TXT format, TXT file not in a correct column format

HI guys, I have created a script to read 1 column in a csv file and then place it in text file. However, when i checked out the text file, it is not in a column format... Example: CSV file contains name,age aa,11 bb,22 cc,33 After using awk to get first column TXT file... (1 Reply)
Discussion started by: mdap
1 Replies
Login or Register to Ask a Question