473,378 Members | 1,140 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

shell scripts relating removing leading characters

14
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
Mar 25 '08 #1
6 2766
ashitpro
542 Expert 512MB
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.
Mar 26 '08 #2
creeds
14
[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
Mar 27 '08 #3
ashitpro
542 Expert 512MB
[quote=creeds]
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..
Mar 27 '08 #4
creeds
14
[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
Mar 28 '08 #5
ashitpro
542 Expert 512MB
[quote=creeds][quote=ashitpro]
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)
Mar 28 '08 #6
creeds
14
[quote=ashitpro][quote=creeds][quote=ashitpro]

hey buddy
thanks that was clear n clever logic
regards,
creeeds
Mar 28 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: eichin | last post by:
One of my recent projects has involved taking an accretion of sh and perl scripts and "doing them right" - making them modular, improving the error reporting, making it easier to add even more...
10
by: Daven Nair | last post by:
Hi, I would like to know if Python supports codes similar to shell scripts: count=`ps -ef|grep "pattern"|wc -l` for count in `echo $count` do done fi
9
by: Jeff Wagner | last post by:
I have a project of converting numerous DOS cmd shell scripts to Python. Is there a tutorial to getting started? Thanks, Jeff
2
by: Ryan Gaffuri | last post by:
Ill also need to return values. How do I do this? Im using GNU on solaris 2.8 with korn shell scripts?
0
by: paulhjwu | last post by:
Hi, I have problems running a couple of shell scripts from PHP. I found a similar posting, so I posted my question to the original author. But unfortunately the original author is not at the...
1
by: sainathr | last post by:
Hi, I would like to run shell scripts with respect to the time mentioned in postgres data base tables. Postgres database should trigger the shell script for the time mentioned in the table. To...
0
by: skyineyes | last post by:
Hi Can anybody provide information on accessing DB2 database through UNIX shell scripts. Any tutorial will ne highly appreciated. Thanks
0
by: skyineyes | last post by:
Hi Can anybody provide information on accessing DB2 database through UNIX shell scripts.Any tutorial will ne highly appreciated. Thanks
1
by: creeds | last post by:
Hello , I am thinking of performing databse operation using shell scripts , for example i am in need to delete sum number from database very often so if i just run a shell scripts and give that...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.