![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | 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. |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
sed help.
frnds,
I have lots of files .. the contents of these files are semicolon delimited. like Cmpabc;20080215;20080215082141;20080215082812;199483;43188746 i want to insert 1 more value in the beginning... ( there are 2 options for this value depends on the file name...) I 'll handle that with if.. ( m i right ??? ) so , like after the operation ..the content sud be X;Cmpabc;20080215;20080215082141;20080215082812;199483;43188746 more details lets i have 2 files X_ABC.dat and Y_ABC.dat so i want to insert X for the first file n Y for the second .... pl help... -anchal. |
| Forum Sponsor | ||
|
|
|
|||
|
This problem looks awful, but is quite simple once you know that you can address the whole matched expression by a "variable": "&". Here is an example:
Code:
print "hello world" | sed 's/^.*$/=&=/' Hence, if you want to insert "X;" at the beginning of the line: Code:
sed 's/^.*$/X;&/' /your/file Code:
sed 's/^.*$/'"$var"';&/' /your/file I hope this helps. bakunin |
|
|||
|
frnds..,
I m lltle messed up while implementing this logic.... :-( actually... as i already wrote here that I want to prepend "X;" only if filenames contains X. and "Y;" if filenames contains Y. this is what i did.. ( code shown for this part only.. ) for FILENAME in `ls -1 $FileDir/ABC_?_123.tmp` do FOUND=`ls -1 $FileDir/ABC_?_123.tmp | grep X` if [ "$FOUND" ] then TMP=tmpfile_$$ sed -e 's/^.*$/X;&/' < $FILENAME > $TMP mv $TMP $FILENAME else echo "The file $FILENAME does not include the word X" fi done now what happenps is.. I got all my files with "X;" prepended to them.., which comes under the for loop condition... what cud be the prob? or can any1 suggest any other logic?? thanks.. |
|||
| Google UNIX.COM |
| Thread Tools | |
| Display Modes | |
|
|