![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| sed replace with fixed length | McLan | Shell Programming and Scripting | 7 | 05-14-2008 11:57 PM |
| What the command to find out the record length of a fixed length file? | tranq01 | UNIX for Dummies Questions & Answers | 3 | 10-19-2007 11:16 AM |
| Awk with fixed length files | c2b2 | Shell Programming and Scripting | 7 | 01-06-2007 09:57 AM |
| fixed length fields in awk | roopla | Shell Programming and Scripting | 2 | 11-13-2006 06:12 PM |
| creating a fixed length output from a variable length input | r1500 | Shell Programming and Scripting | 2 | 12-03-2003 10:09 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
fixed record length
hello!
I have a file with fixed record length... format: 123445asdfg 4343777 sfgg I wanna convert it to 123445,asdfg ,4343,777 ,sfgg is there any way to do it? sed/grep/awk?? at the moment I use sed -e 's_ \([^ ]\)_,\1_g' but it works only if there are spaces between records... any idea to deal with?? thanks for any help. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
it seems you know awk,
so you can use substr function of awk, do man awk for more details Gaurav |
|
#3
|
||||
|
||||
|
Code:
echo "123445asdfg 4343777 sfgg"|awk '{print substr($1,1,6)","substr($1,7,11)" ,"substr($2,1,4)","substr($2,5,7)" ,"$3}'
123445,asdfg ,4343,777 ,sfgg
|
|
#4
|
|||
|
|||
|
thanks a lot!
is there a more generic way to do it? instead of $1/$2....to parse the whole line? becouse like this I will have to change the script each time I use it for another file. thanks for any advise. |
|
#5
|
|||
|
|||
|
if you are sure that the no. of characters in the string is going to be constant, then you can first use sed to remove the blank spaces fron it and then use the awk substr() fn to print the required output.
Quote:
Gaurav |
|
#6
|
|||
|
|||
|
it doesn't solve the problem...
in each file I have to change substr parameters instead of substr($1,7,11)" ,"substr($2,1,4)","substr($2,5,7)" I want substr($the_whole_line,7,11),substr($the_whole_line,12,17) ls that possible? thanks. |
|
#7
|
|||
|
|||
|
fields in a record which is lets say 30 chars another is 40 may contain spaces...
|
|||
| Google The UNIX and Linux Forums |