![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| To remove new line character | shihabvk | UNIX for Advanced & Expert Users | 7 | 06-18-2009 07:44 AM |
| How to remove extraneous character | vsmurali | UNIX for Dummies Questions & Answers | 7 | 03-18-2008 12:57 PM |
| Search term and output term in desired field | Raynon | Shell Programming and Scripting | 28 | 03-04-2007 02:34 AM |
| Create a Term & Run chars on this Term | the_tical | High Level Programming | 1 | 08-12-2003 09:18 PM |
| Remove Last Character of Line | danhodges99 | Shell Programming and Scripting | 4 | 05-21-2003 09:30 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Remove last character of a term
Hi All,
I have a few terms with a comma as the last character. Can any experts show me how to remove the last character? Note the the length of the term is not fix. Input: 1, 2, 12, 14, 103, 198, 3006, Output, 1 2 12 14 103 198 3006 |
|
||||
|
Hi, Raynon -
Two easy ways, asusming you're using a file: 1. awk -F',' '{print $1}' infile > outfile 2. cut -d',' -f1 infile > outfile I've quoted the comma delimiter in both cases to demonstrate that you should use quotes if the delimiting character could possibly be interpreted by the shell (such as $ or *). Hope this helps, John |
|
||||
|
Thks John and Frankin,
They worked jus fine. !!! Cool!! Just a small problem, how can i incorporate above " awk -F',' '{print $1}' " to the below code to the statement in blue?? I am expecting my 3rd field to be smiliar to for eg " 15, " but i only want to capture " 15 ". Can you help ? Code:
$1 == "Device" && $2 == "id" {
#print;
unit_no = $3;
flag = 1}
flag > 0 && flag < 4 && $9 == "Device" && $10 == "Sort" {
print flag;
printf ("%s %s\n",unit_no,$0)
flag++;
}
flag > 3 {flag = 0}
Last edited by Raynon; 03-19-2008 at 11:02 AM.. |
|
||||
|
Quote:
Code:
unit_no=$(echo $3 | awk '{print substr($0,1,match($0,/\,/)-1)}')
|
|
||||
|
Quote:
Hi Franklin, Thks that's clean. |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|