Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cut command 1

Status
Not open for further replies.

tijerina

Vendor
Mar 4, 2003
132
US
I am trying to use the following command but my permanent file is not changing? Why?

cat AUDITISS | cut -c21-

I am trying to cut the 21 character to the end of the line.

/SYS3/PRDSCHED/SS013902
/SYS3/PRDSCHED/SS017902
/SYS3/PRDSCHED/SS029902
/SYS3/PRDSCHED/SS030902
/SYS3/PRDSCHED/SS049902
/SYS3/PRDSCHED/SS068902
/SYS3/PRDSCHED/ST501902
/SYS3/PRDSCHED/STARTITO
/SYS3/PRDSCHED/STOPITO
/SYS3/PRDSCHED/STSYSTM
/SYS3/PRDSCHED/TEMPFILE
 
Because you didn't tell it to.
Redirect the output to a temp file and then replace the original file with the temp file.


cat AUDITISS | cut -c21- > tempfile
mv tempfile AUDITISS
 
ex - AUDITISS <<EOF
%s/^\(.\{21\}\).*/\1/
wq!
EOF

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Hemo,

Thanks but the output I am looking for is not the cut pieces. This is what I need:

/aaaaaa/bbbbbbb/ccccc/xxxxx

The output should be:

/aaaaaa/bbbbbbb/ccccc

Hope I am making sense.
 
echo '/aaaaaa/bbbbbbb/ccccc/xxxxx' } | sed -e 's=^\(.\{21\}\).*=\1='

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
ooops, sorry - all ONE line:

echo '/aaaaaa/bbbbbbb/ccccc/xxxxx' | sed -e 's=^\(.\{21\}\).*=\1='

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Thanks to all but this is not working.

What I have is:

/SYS3/PRDSCHED/SS013902
/SYS3/PRDSCHED/SS017902
/SYS3/PRDSCHED/SS029902

When I find the command that will work, the results should look like:

/SYS3/PRDSCHED/SS013
/SYS3/PRDSCHED/SS017
/SYS3/PRDSCHED/SS029

All want to do is take out the last three characters of the file name.

I tried all the suggestions but they are not working.

Anymore ideas???


 
echo '/SYS3/PRDSCHED/SS013902' | sed -e 's=^\(.\{20\}\).*=\1='

seem to work for me

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Okay, Okay,

Sorry for the lack of direction on my end.

I have all these files in one file, so if you cat LISSTFILE
then you will see a list of '/SYS3/PRDSCHED/SS013902' files. How do I go into this LISTFILE and cut all the last three characters of every line that has a file name longer than 5 characaters?
 
In my prev. posts I was giving the examples of the RE to cut every line to less-then 21 chars in length. This is the inline version using 'ex'.

ex - LISSTFILE <<EOF
%s=^\(.\{20\}\).*=\1=
wq!
EOF

Your new definition of what needs to be done is a bit harder to do as you have 'file name longer than 5 characaters' requirement. I'd suggest posting to the 'UNIX Scripting' forum - you might get helped there.

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top