 | 
March 25th, 2008, 11:36 AM
| | Newbie | | Join Date: Feb 2008
Posts: 13
| | shell scripts relating removing leading characters
hello,
I have some problems regarding trimming the leading character
awk -F"|" '{print $1"|"$2"|"$3"|3|"$4}' /home/postgres/$File-9898.txt.edt > /home/postgres/edt1/$File-9898.txt.edt1
After getting the file $File-9898.txt.edt1, i am in need to limit the $4 parameter to 14 length so i want to trim everything if that extends more than 14.
so, how can i proceed,
with regards
creeds
| 
March 26th, 2008, 12:17 PM
|  | Expert | | Join Date: Aug 2007
Posts: 297
| | Quote: |
Originally Posted by creeds hello,
I have some problems regarding trimming the leading character
awk -F"|" '{print $1"|"$2"|"$3"|3|"$4}' /home/postgres/$File-9898.txt.edt > /home/postgres/edt1/$File-9898.txt.edt1
After getting the file $File-9898.txt.edt1, i am in need to limit the $4 parameter to 14 length so i want to trim everything if that extends more than 14.
so, how can i proceed,
with regards
creeds |
use printf instead of print with awk,and specify the format specifier for last field.
Somthing like below:
awk -F"|" '{printf "%s|%s|%s|3|%.14s\n" ,$1,$2,$3,$4}' /home/postgres/$File-9898.txt.edt > /home/postgres/edt1/$File-9898.txt.edt1
everything will be redirected to $File-9898.txt.edt1 file.
Pay attention for two things.
1: ".14" number, which is field width specifier.
2: \n at the end of string..I am not sure about this..check out yourself.
| 
March 27th, 2008, 07:50 AM
| | Newbie | | Join Date: Feb 2008
Posts: 13
| |
[quote=ashitpro]
thanks for the solution..
yeah i also cud dothat using substr(), so that i can count 14, but if i want to cout 14 from the last , what patterns i have to apply ...
how to modify the following lines which limits 4th file dto first 14th limit
awk -F"|" '{printf "%s|%.14s|%s|3|%s\n" ,$1,$2,$3,$4}'
with regards,
Creeds
| 
March 27th, 2008, 12:02 PM
|  | Expert | | Join Date: Aug 2007
Posts: 297
| |
[quote=creeds] Quote: |
Originally Posted by ashitpro thanks for the solution..
yeah i also cud dothat using substr(), so that i can count 14, but if i want to cout 14 from the last , what patterns i have to apply ...
how to modify the following lines which limits 4th file dto first 14th limit
awk -F"|" '{printf "%s|%.14s|%s|3|%s\n" ,$1,$2,$3,$4}'
with regards,
Creeds | Thats what I said in my previous post..
Put the '.14' between '%' and 's'.
same as you've done for printing $2
So modified commandshould look like:
awk -F"|" '{printf "%s|%.14s|%s|3|%.14s\n" ,$1,$2,$3,$4}'
Now your last field will have only 14 characters..
| 
March 28th, 2008, 05:52 AM
| | Newbie | | Join Date: Feb 2008
Posts: 13
| |
[quote=ashitpro][quote=creeds]
sorry yar,
i got ur answer and the pattern in the very first reply so no problem with any field being limited to 13 or 14 wotsever...
its understandable,
but inthe last post i wanted to count 14 from the last,
i mean +009779841366128 i want to remove + 00 as i limit my parameter to 14 from last....so how to proceed,
just sort my problem out man,
with regards,
Suman
| 
March 28th, 2008, 08:04 AM
|  | Expert | | Join Date: Aug 2007
Posts: 297
| |
[quote=creeds][quote=ashitpro] Quote: |
Originally Posted by creeds sorry yar,
i got ur answer and the pattern in the very first reply so no problem with any field being limited to 13 or 14 wotsever...
its understandable,
but inthe last post i wanted to count 14 from the last,
i mean +009779841366128 i want to remove + 00 as i limit my parameter to 14 from last....so how to proceed,
just sort my problem out man,
with regards,
Suman | check out this, modify according to you
awk -F"|" '{printf "%s|%.14s|%s|3|%s\n" ,$1,$2,$3,substr($4,length($4)-13,length($4))}'
Note:If you substract 13 it will print 13+1 characters in last field(ofcourse counting from last character)
| 
March 28th, 2008, 11:14 AM
| | Newbie | | Join Date: Feb 2008
Posts: 13
| |
[quote=ashitpro][quote=creeds][quote=ashitpro]
hey buddy
thanks that was clear n clever logic
regards,
creeeds
|  |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over network members.
|