Hi All,
I want to extract the integers from the each line, each line may have 2 or more integers.
The following command is appending each integers.
echo "Hi I am 100, my friend is 500, his friend is 423" | sed "s/[^0-9]//g"
100500423
I need to have delimiter "|" between the integers. If anyone knows the command, please share with me.
mo@mo-laptop:~/scripts$ echo "Hi I am 100, my friend is 500, his friend is 423" | grep -o [0-9]* | awk 'BEGIN{ ORS="|" } { print $1 } END { print "\n"}'
100|500|423|
|mo@mo-laptop:~/scripts$
Hi Scrutinizer, the following is not giving any output in SunOS.
echo "Hi I am 100, my friend is 500, his friend is 423" |sed -n 's/[^0-9]\+/|/gp'
No outout for the above cmd.
echo "Hi I am 100, my friend is 500, his friend is 423" | grep -o [0-9]* | awk 'BEGIN{ ORS="|" } { print $1 } END { print "\n"}'
grep: illegal option -- o
Usage: grep -hblcnsviw pattern file . . .
Hi Franklin52, I modified your command little bit, and it works perfectly for one line input.
echo "update emp set emp_id='5000100' where emp_id='7894561';" | nawk -F"[ ']" '{for(i=1;i<=NF;i++){if(int($i)==$i){s=s?s"|"$i:$i}}print s}'
5000100|7894561
I have file tt.txt which has 2 lines in it.
cat tt.txt
update emp set emp_id='5000100' where emp_id='7894561';
update emp set emp_id='5000200' where emp_id='5894561';
dude, not to sound like an ass, but maybe you should at least try and figure out how to transcribe the above code for your system. i mean, you can't expect us to write code and figure out how to make it work on your system.
the theory doesn't change, just the syntax. the tools on your OS probably differ slightly from the ones we use. go check the man pages and figure out how to change the code appropriately. if your system doesn't take the grep -o (which outputs only the pattern), check your docs and figure out what the equivalent option is for your OS.