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!

Strip character from the end of each line 1

Status
Not open for further replies.

630111

MIS
Oct 30, 2001
127
US
When I run nsrjb | grep [-*] it outputs the following result...

19:
38:
59:
64:
91:
114:

What awk statement do I use to get rid of the : at the end of each line?

Thanks!
630111
 


nawk -F ":" '{print $1}' d.txt

sed -e 's/\(.*\):[ ]*$/\1/g' d.txt vlad
+---------------------------+
|#include<disclaimer.h> |
+---------------------------+
 
Code:
nawk -F &quot;:&quot; '{print $1}' d.txt
work if there is only one ':' character in the line as in the given data sample.

In this case, you could also use the cheaper command
Code:
cut -d: -f1 < d.txt

The sed equivalent of the previous commands is
Code:
sed -e 's/:.*//' d.txt

To suppress only the ':' at the end of the line even if there are other ':' in the line:
Code:
sed -e 's/:$//' d.txt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top