How to trim a 419th column in UNIX file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to trim a 419th column in UNIX file.
# 1  
Old 01-14-2009
How to trim a 419th column in UNIX file.

Hi All,

I have a UNIX file, which has Total of 532 column, each delimited with ^~^. One of the column (419) is 202 character long. In real case, it should be 22 character long.

cut -d~ -f419 filename

^404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040402 D2D404D4450444040604048E040404240C0404040
42404040404040584042544040404044404040404040404040404040404040^

I need to trim it to 22 character. at the begining & end ^ sould come. I have searched & found following link.
https://www.unix.com/unix-dummies-que...-perl-awk.html

But when i execute the command given here, AWK is not supporting it.

Can some one help me?
# 2  
Old 01-14-2009

What does "not supporting it" mean? What does happen? What did you expect to happen? What did you want to happen?

What is the exact script you are running?

# 3  
Old 01-14-2009
It gives following error.

$ awk 'NR==1{print;next}{$419=substr($419,180)}1' ABC20090112.OUT > aaa
awk: trying to access field 419

all record(columns) are delimited with ^~^ & there are 532 columns.

From my data file i want to trim 419th column from 202 characters to 22 characters , so that i can load it.
# 4  
Old 01-14-2009

You must tell awk that your fields (not records) are tilde delimited:

Code:
awk -F~ 'NR == 1 { .... } ....' ....

# 5  
Old 01-14-2009
It gives same error.

$ awk -F~ 'NR==1{print;next}{$419=substr($419,180)}1' ABC20090112.OUT > aaa
awk: trying to access field 419

or

$ awk -F^~^ 'NR==1{print;next}{$419=substr($419,180)}1' ABC20090112.OUT > aaa
awk: trying to access field 419
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to trim the file names?

How do i get the following output, irrespective of how many . 's i will have the file name. Input: FCBTexas_2013_12_31_16_V2.5_Masked.xml.filepart Output: FCBTexas_2013_12_31_16_V2.5_Masked.xml Thank you. (6 Replies)
Discussion started by: Ariean
6 Replies

2. UNIX for Advanced & Expert Users

Copy a column to another column in UNIX fixedwidth file

Hi All, I have a fixedwidth file of length 3000. Now i want to copy a column of 4 chars i.e( length 1678-1681) to column 1127 – 1171 to the same file. Please let me know how can i achive using a single command in fixed width file. Also source column length is 4 chars and target column length... (4 Replies)
Discussion started by: kiranparsha
4 Replies

3. Shell Programming and Scripting

trim spaces in unix for variable

HI Guys I have written a script using awk to split a file based on some identifier and renaming the file based on two values from specific length. ts a fixed width file. When I am trying to fetch the values a = substr($0,11,10) b = substr($0,21,5); i am getting spaces in a and b values .... (6 Replies)
Discussion started by: manish8484
6 Replies

4. Shell Programming and Scripting

right trim at end of file

Hi, I'have a file as below I need to replace the comma at the end of the file into ) as below Thanks (1 Reply)
Discussion started by: dvah
1 Replies

5. Shell Programming and Scripting

How to trim a string in unix shell script

I am reading a string like $/folder1/folder2/filename from a file And I am storing it in a variable say $path. I want to store the path within single quotes in order to use the path within a command. if i set like path="'"$path"'" echo $path It is printing like ' $/folder1/folder2/filename'... (6 Replies)
Discussion started by: Shri123
6 Replies

6. UNIX for Dummies Questions & Answers

Trim and pad a field in the middle of unix file

Hello, I have a file with several lines and I need to trim and pad with spaces the data that are between position 6 and 15 included. Data in position 1 to 5 and after 15 could be anything, and should stay as they are. For instance, the following records in a file (underscore = space)... (4 Replies)
Discussion started by: BSF
4 Replies

7. Shell Programming and Scripting

Trim pathname of the file

I am capturing the files in a directory to an array. I have 2 arrays with list of files in two different directories. Both the directories are supposed to have the same number of files and filenames. I want to check that the same file exists in both the directories. After I capture the... (1 Reply)
Discussion started by: Sangtha
1 Replies

8. UNIX for Dummies Questions & Answers

Trim String in 3rd Column in Tab Delimited File...SED/PERL/AWK?

Hey Everybody, I am having much trouble figuring this out, as I am not really a programmer..:mad: Datafile.txt Column0 Column1 Column2 ABC DEF xxxGHI I am running using WGET on a cronjob to grab a datafile, but I need to cut the first three characters from... (6 Replies)
Discussion started by: rickdini
6 Replies

9. UNIX for Dummies Questions & Answers

trim file

Hi, I have a 6G log , which is unusual to read and I want to minimize it by removing some part on the upper portion( around 4GB). what should i do? can you please help me? thanks. (1 Reply)
Discussion started by: tungaw2004
1 Replies

10. UNIX for Dummies Questions & Answers

trim leading zero in certain column in a string

I would like to know how to trim leading zero only in certain column of of a string, example: hdhshdhdhd000012mmmm0002abc <===== before hdhshdhdhd 12mmmm 2abc <===== after Thanks for your help. (2 Replies)
Discussion started by: dngo
2 Replies
Login or Register to Ask a Question