1827473 Members
1709 Online
109965 Solutions
New Discussion

Pattern substitution

 
SOLVED
Go to solution
Chern Jian Leaw
Regular Advisor

Pattern substitution

I would like to remove the following patterns i.e find: and also :Permission denied from my file, f1, and maintain only the second field i.e /fs36/nwd/f1 and /fs36/nwd/f1/audio. The file f1 has the following format:

find: /fs36/nwd/f1 :Permission denied
find: /fs36/nwd/f1/audio :Permission denied

How do I write a csh script to do that? What is the single command utility does the job?

Thanks.
6 REPLIES 6
steven Burgess_2
Honored Contributor

Re: Pattern substitution

Hi

command to use

cat file | awk -F : '{print $2}' > file2

Hope this helps

Steve
take your time and think things through
Chern Jian Leaw
Regular Advisor

Re: Pattern substitution

Thanks. I tried the following on file f1, but it did not work
%s/find:/ /g
%s/:Permission denied/ /g
steven Burgess_2
Honored Contributor
Solution

Re: Pattern substitution

Hi

From the command line

sed s/find://g f1
sed s/:Permission denied//g f1

I'll put in a script as well

Steve

take your time and think things through
steven Burgess_2
Honored Contributor

Re: Pattern substitution

Hi

After using vi to edit the file

%s/find:/ /g

Your method also works

Steve
take your time and think things through
John Carr_2
Honored Contributor

Re: Pattern substitution

Hi

cat f1 | grep -v "Permission denied" > newfile


cheers
John.
John Carr_2
Honored Contributor

Re: Pattern substitution

HI

please ignore my last response I misread the question the grep -v will remove the full line from the file.

cat f1 | cut -f2 > newfile

John