Cutting columns starting at the end of each line...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cutting columns starting at the end of each line...
# 1  
Old 11-07-2008
Cutting columns starting at the end of each line...

Hi Guys,


Can you help me with a sed or a csh script that will have an output from the input below. Cutting the columns starting from the end of the line and not from the start of the line?

Sample1 - The underscore character "_" is actually a space...i need to put it as underscore here coz the characters are right-justified and it doesn't show the correct format when i post the data here...

input:
++++
D_1_
T_6_
1_5_
_19_
_23_
_30_
_37_
_65_
105_
201_

output:
+++++
1
6
5
19
23
30
37
65
105
201


Sample2 - Same as sample 1 only truncate the space from Sample1 and change to comma then cut and get the data with reference to the last comma in the line:

input:
++++
D,1,
T,6,
,19,
,23,
,30,
,37,
,65,
105,
201,

output:
+++++
1
6
19
23
30
37
65
105
201


Let me know...Thanks a lot for your time guys!
# 2  
Old 11-07-2008
echo "1_2_233_33" | awk -F"_" '{x=NF-1 ;print $x}'
233
# 3  
Old 11-07-2008
Quote:
Originally Posted by demwz
echo "1_2_233_33" | awk -F"_" '{x=NF-1 ;print $x}'
233
Hi demwz...that was quick...i used your code for the csv sample2 and works like a charm ---> awk -F"," '{x=NF-1 ;print $x}'

thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

With script bash, read file line per line starting at the end

Hello, I'm works on Ubuntu server My goal : I would like to read file line per line, but i want to started at the end of file. Currently, I use instructions : while read line; do COMMAND done < /var/log/apache2/access.log But, the first line, i don't want this. The file is long... (5 Replies)
Discussion started by: Fuziion
5 Replies

2. UNIX for Dummies Questions & Answers

Cutting specific columns from lines

I am trying to remove columns 81-97 from a line that can be as long as 114 characters. Because a number of lines might not have under 80 characters, using the cut command following by paste could be a problem. While sed might work, is there some other utility that could do this more easily? ... (9 Replies)
Discussion started by: wbport
9 Replies

3. Shell Programming and Scripting

Adding info to end of line if two columns match from files with different separators

I have two files (csv and vcf) which look exactly like this S1.csv func,gene,start,info "exonic","AL","2309","het" "exonic","NEF","6912","hom"S1.vcf ##fileinfo #CHROM POS ID INFO chr1 4567 rs323211 1/1:84,104,99 chr4 2309 rs346742 1/1:27,213,90 chr6 5834 ... (5 Replies)
Discussion started by: Sarah_19
5 Replies

4. Shell Programming and Scripting

Remove the spaces at the end of a line starting from a fixed position

I want to remove the trailing spaces at the end of each line starting from a particular position(using ksh script). For example, in the attached file, I want to remove all the spaces starting from the position 430 till the end. The space has to be removed only from the 430th position no matter in... (3 Replies)
Discussion started by: Suryaaravindh
3 Replies

5. Shell Programming and Scripting

Cutting file name from end

Dear Friends, I want to take last 10 characters of a file name in a variable. E.g. file name is 123432311234567890.txt then we want "1234567890" to be taken in an variable. Request you to guide me to do the same Thanks in anticipation Anushree (7 Replies)
Discussion started by: anushree.a
7 Replies

6. Shell Programming and Scripting

Remove line starting from space till end.

Hi, I have a code tag, from which i have the below snippet: intelrpt.GetCMB_FB type=ODBC> intelrpt.GetCMB_FB type=SYBASE> I want the output like: intelrpt.GetCMB_FB intelrpt.GetCMB_FB That is remove the lines starting from WHITESPACE till end. Please help. I am new to... (7 Replies)
Discussion started by: anupdas
7 Replies

7. Shell Programming and Scripting

Grep from a starting line till the end of the file

Hi Folks, I got to know from this forums on how to grep from a particular line say line 6 awk 'NR==6 {print;exit}' But how do i grep from line 6 till the end of the file or command output. Thanks, (3 Replies)
Discussion started by: Mr. Zer0
3 Replies

8. Shell Programming and Scripting

Print starting 3rd line until end of the file.

Hi, I want to Print starting 3rd line until end of the file. Pls let me know the command. Thanks in advance. (1 Reply)
Discussion started by: smc3
1 Replies

9. AIX

CUT command - cutting characters from end of string

Hello, I need to delete the final few characters from a parameter leaving just the first few. However, the characters which need to remain will not always be a string of the same length. For instance, the parameter will be passed as BN_HSBC_NTRS/hub_mth_ifce.sf. I only need the bit before the... (2 Replies)
Discussion started by: JWilliams
2 Replies

10. Shell Programming and Scripting

Cutting Columns and Moving in to a file

Guys, Can any one tell me how can we cut the columns and move each column in to a separate file using awk? I have a tab delimited file as shown below, 1213 wattt werree 2345 skhasdjh aasas I want to output this in to three files named a.txt,b.txt and c.txt say a.txt... (3 Replies)
Discussion started by: Serious Sam
3 Replies
Login or Register to Ask a Question