Hi
I am using "grep" command to get certain pattern out of the file:
PNUM=34
$ grep -w "#${PNUM}" myfile
#34 * 2297 * 410 * 964 * * 4352
$
Is there a way to retrieve the section of the above output without #34 so the output would look like this:
* 2297 * 410 * 964 * * 4352
Thanks
clx
2
try:
echo "#34 * 2297 * 410 * 964 * * 4352" | sed -n '/#34/ s/#34//p'
jp2542a
3
Awk script (snip.awk):
{
for( i = 1; i <= NF; i++)
if ( $i !~ /#34/ ) # your pattern goes here
printf "%s ", $i
printf "\n"
}
Data file (myfile):
#34 * 2297 * 410 * 964 * * 4352
#44 * 244 * 43 * 4 4 4
#55 * #34 * * * * ddd * *
Output:
# awk -f snip.awk myfile
* 2297 * 410 * 964 * * 4352
#44 * 244 * 43 * 4 4 4
#55 * * * * * ddd * *
danmero
4
Shorter :rolleyes:
# PNUM=34
# awk '{sub("^#'$PNUM' ","")}1' file
* 2297 * 410 * 964 * * 4352
#44 * 244 * 43 * 4 4 4
#55 * #34 * * * * ddd * *
# sed "s/^#$PNUM //" file
* 2297 * 410 * 964 * * 4352
#44 * 244 * 43 * 4 4 4
#55 * #34 * * * * ddd * *