Operating System - HP-UX
1833873 Members
2504 Online
110063 Solutions
New Discussion

Re: How to Manipulate Text File

 
SOLVED
Go to solution
george_114
Advisor

How to Manipulate Text File

How to manipulate textfile x to become xt using script.Content of xt :

970 /etc/hosts
976 /etc/passwd
980 SO122310000123

Thanks in advanced for your help.
9 REPLIES 9
RAC_1
Honored Contributor

Re: How to Manipulate Text File

Confusing. What exactly you want?

File xt to look like as follows?
970 /etc/hosts
976 /etc/passwd
980 SO122310000123

Post.
There is no substitute to HARDWORK
george_114
Advisor

Re: How to Manipulate Text File

Yes RAC the xt file look like :
970 /etc/hosts
976 /etc/passwd
980 SO122310000123


RAC_1
Honored Contributor
Solution

Re: How to Manipulate Text File

cat xt|grep -i "pinguin"|awk '{print $4, $5}'

Hope this helps.
There is no substitute to HARDWORK
Elmar P. Kolkman
Honored Contributor

Re: How to Manipulate Text File

One AWK can do the trick too, and not only for pinguin print jobs, by ignoring all lines until the header line, like this:

awk '
started==1 { print $4,$5 }
$1 == "Rank" { started=1 }
' xt
Every problem has at least one solution. Only some solutions are harder to find.
george_114
Advisor

Re: How to Manipulate Text File

RAC, do you have other alternative solution without using awk ???Because my UNIX SILENT command can not proses awk statement.Thanks in advance.
RAC_1
Honored Contributor

Re: How to Manipulate Text File

cat xt|grep -i "pinguin"|cut -d " " -f4 -f5
There is no substitute to HARDWORK
Elmar P. Kolkman
Honored Contributor

Re: How to Manipulate Text File

grep -i pinguin x | cut -c36-50 > xt
(I can be mistaken in the numbers, but something like this should work)
Every problem has at least one solution. Only some solutions are harder to find.
john korterman
Honored Contributor

Re: How to Manipulate Text File

Hi,
try this simple approach, using xt as $1:

#!/usr/bin/sh
while read a b c d e f g
do
echo $b | grep -q pinguin@localhost
if [ $? = 0 ]
then
echo $d $e
fi
done <$1

regards,
John K.
it would be nice if you always got a second chance
David Totsch
Valued Contributor

Re: How to Manipulate Text File

If the first six lines of the output is always the same and the data you are looking for is always in the same colums...

sed -n "7,$ p" x | cut -c41-66

Enjoy,
-dlt-