![]() |
|
|
|
|
|||||||
| 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 |
| editing ELF file | tejuwala | Linux | 1 | 05-17-2008 08:22 PM |
| Editing File using awk/sed | Mohammed | Shell Programming and Scripting | 4 | 05-16-2007 08:00 AM |
| Editing the File using Awk | awk_beginner | Shell Programming and Scripting | 3 | 04-06-2007 07:43 AM |
| Help with editing file | dsravan | Shell Programming and Scripting | 4 | 01-31-2007 09:59 AM |
| File editing using awk | rinku11 | Shell Programming and Scripting | 2 | 11-23-2006 07:34 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Editing file
Hi,
I am in a situation wherein am getting file file certailn values suppose 1u56979hhghhklklkkkjkjkjk 0 0 0 The file will have values like above only. I need to add another field of NULL value(of length 9) at the end of first column i.e. It should like this after editing: 1u56979hhghhklklkkkjkjkjk<NULL> 0 0 0 Kindly help. |
| Forum Sponsor | ||
|
|
|
|||
|
Rahul,
It sounds like you're trying to NUL terminate the first (whitespace delimited) field (word) of each line in a text file. That's a very odd request (because the ASCII NUL character is normally used to terminate strings ... but normally NOT embedded in text files ... so many tools that might be trying to read the file line by line would not handle the NUL character gracefully. It's also possible that your shell or your copy of sed or whatever cannot handle this cleanly. So you might need to use GNU versions of these tools, or a copy of Perl or Python (or compile up a little utility in C, of course). The most obvious attempt in plain bash would be: Code:
#!/bin/bash
while IFS="" read line; do
set -- $line
first_word="$1"
shift
echo -e "$firstword\000$*"
done
That might have some odd artifacts (due to the way that each line is parsed by the set -- command). This following one-liner works in two stages, using sed the first space on each line to a character "177" (octal) --- hex 0x7F, a.k.a. the "DEL" character; and then using the tr command to change that into an ASCII NUL: Code:
sed -e 's/ /'$(echo -ne '\177')'/' /tmp/foo | tr '\177' '\00' | cat -A JimD (former Linux Gazette AnswerGuy) |
|
|||
|
oops...seems we are not on same page !
He JimD
Thanks for your effort ! But I think we are not on same path....! Let me explain my requirement more simply now,... In my file I am getting rows as like this : Code:
1US500100010000010001920077000131973511115107128101771004460001204600004 0 0 0 0 1US500100010000010001920077000131973511115122115101771004460000889600007 0 0 0 0 1US500100010000010001920077000131973511115122115101771004460000889600848 0 0 0 0 1US500100010000010001920077000131973511115145123103111004129440199600034 0 0 0 0 1US500100010000010001920077000131973511115145123103111004129440199611798 0 0 0 0 1US500100010000010001920077000131973511115145123105731004129440254200959 0 0 0 0 1US500100010000010001920077000131973511151213161106591004460083113503316 0 0 0 0 1US500100010000010001920077000131973511151213161106591004460083246011470 0 0 0 0 1US500100010000010001920077000131973511617125150106821001258770530508226 0 0 0 0 1US500100010000010001920077000131973511617125150106821001258770530511107 0 0 0 0 1US500100010000010001920077000132240211115145123103111004129440199600034 0 0 0 0 1US500100010000010001920077000132240211115145123103111004129440199611798 0 0 0 0 Now I need to add an extra field og length-9 after first column with NULL value. So after editing a row should look like this: 1US500100010000010001920077000131973511115107128101771004460001204600004 0 0 0 0 i.e. <1stcolumn value><9 spaces><2nd col value>....and so on.. Let me also tell file has many rows of similar format and size of file is 24mb. Kindly help.... Will wait for your reply. Thanks |
| Thread Tools | |
| Display Modes | |
|
|