02-28-2009
Passing UNIX commands inside sed
Hi,
In sed, is it possible to match patterns by directly executing UNIX commands inside sed?
For e.g. -
sed "s/`cat file.txt | cut -d "|" -f2`/replace_string"
Will the above command work?
My expectation is to search for the second field in file.txt (file delimited by | ) and replace those with replace_string.
I know I could store the output of cat file.txt | cut -d "|" -f2 in a variable and pass it to sed. But I want to know if direct command substitution is possible
Any help is greatly appreciated.
-Thanks
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I am trying to pass a regular expression variable from a simple script to sed
to remove entries from a text file
e.g.
a='aaaa bbbb cccc ...|...:'
then executing sed from the script
sed s'/"'$a"'//g <$FILE > $FILE"_"1
my output file is always the same as the input file !!
any... (5 Replies)
Discussion started by: Daniel234
5 Replies
2. Shell Programming and Scripting
Hi ,
I am having one situation in which I need to run some simple unix commands after doing "chroot" command in a shell script. Which in turn creates a new shell.
So scenario is that
- I need to have one shell script which is ran as a part of crontab
- in this shell script I need to do a... (2 Replies)
Discussion started by: hkapil
2 Replies
3. Shell Programming and Scripting
When my script deals with large input files like 22Gb or 18 GB the basic commands like sort or join fails when run from inside the shell scripts. Can there be any specific reason for this?
For e.g.
sort -u -t "," -k1,1 a.csv > a.csv.uniq"
sort -u -t "," -k1,1 b.csv > b.csv.uniq"
The... (3 Replies)
Discussion started by: esha
3 Replies
4. Shell Programming and Scripting
I am trying a simple sed to replace a pattern but it fails ,,c an someone help in where iam wrong, here is what i run and i get no o/p
a=`cat abc.sh | grep -i pattern1 | egrep -iv "pattern2" `
sed 's/`echo $a`/XYZ=newvalue/g' < abc.sh > abc.sh_new
This is how my ksh -x of teh script looks... (2 Replies)
Discussion started by: yesmani
2 Replies
5. Shell Programming and Scripting
Dear Friends,
Please let me know how to use the date command inside the substitution flag replacement string.
echo "01 Jan 2003:11:00:06 +0100" | sed 's/\(.*\)/`date -d \1 "+%Y%m%d%H%M%S"`/'
I want to supply \1 string to Here mention below as part of replacement string,
date -d <Here>... (5 Replies)
Discussion started by: tamil.pamaran
5 Replies
6. Shell Programming and Scripting
Hi,
I am trying to print a specific line in a file through sed or awk. The line number will be passed as a parameter from the previous step. My code looks as below.
TEMP3=`sed -n '$TEMP2p' $FILEPATH/Log.txt`
$TEMP2, I am getting from the previous step which is a numerical value(eg:3).
... (2 Replies)
Discussion started by: satyasrin82
2 Replies
7. Shell Programming and Scripting
hi everobody
kindly consider the following
in tclsh
I understand that we can do the following
%exec UnixCmd arg1 arg2
but if I assinged the arguments to a list insde tclsh how can I use them back
i.e
%set ArgList
%exec UnixCmd
%exec Unixcmd $list
%exec
all the... (1 Reply)
Discussion started by: Blue_shadow
1 Replies
8. Shell Programming and Scripting
Learning, stumbling! My progress in shell scripting is slow. Now I have this doubt:
I have the following file (users.txt):
AU0909,on
AU0309,off
AU0209,on
AU0109,off
And this file (userson.txt)
AU0909
AU0209
AU0109
AU0309
I just want to set those users on userson.txt to "off" in... (14 Replies)
Discussion started by: quinestor
14 Replies
9. Shell Programming and Scripting
Hello All,
I hope someone could help me with this.
I'm creating a shell script to run a process. The trouble is, part of the process has to be ran as a different user. I can 'su' to the user ok, but I'm having trouble passing a 'cd' command as well as some variables I set earlier in the... (1 Reply)
Discussion started by: bbbngowc
1 Replies
10. UNIX for Advanced & Expert Users
Hello,
i need to pass the variable in place of pwd. how to display variable in the bleow syntax.
suppose, passwd="test", then 'id/$passwd.....
FEDFlagResult=`sqlplus -S 'id/pwd@(DESCRIPTION= (ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1643))(CONNECT_DATA= (SID=peta1)))'<< EOF
select... (4 Replies)
Discussion started by: balareddy
4 Replies