How to read particular line in file from specific column?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to read particular line in file from specific column?
# 8  
Old 01-28-2013
thank u so much pamu... why its
Code:
>>

why not
Code:
>

and I am using this to sort files in ascending order but *.txt not coming in order
Code:
for file in `ls *.txt |sort -t"-" -k2n,2`; do

# 9  
Old 01-28-2013
Quote:
Originally Posted by nex_asp
thank u so much pamu... why its
Code:
>>

why not
Code:
>

Because > is used to overwrite to the file or create new file and >> is used for appending data into file.


Quote:
Originally Posted by nex_asp
and I am using this to sort files in ascending order but *.txt not coming in order
Code:
for file in `ls *.txt |sort -t"-" -k2n,2`; do

Fisrt, is all your files having - in their file name?
Please provide outpur of ls *.txt
# 10  
Old 01-28-2013
here is list of one of my files in one folder for which I am trying...

Code:
gs_10.asc    ts_104a.asc  ts_16.asc   ts_2a.asc  ts_43.asc  ts_58.asc  ts_71.asc  ts_86.asc   ts_95a.asc  tse_6.asc  tss_6.asc
gs_2.asc     ts_104.asc   ts_17a.asc  ts_2.asc   ts_44.asc  ts_59.asc  ts_72.asc  ts_87.asc   ts_95.asc   tse_7.asc  tss_7.asc
gs_3.asc     ts_105a.asc  ts_17.asc   ts_30.asc  ts_45.asc  ts_5a.asc  ts_73.asc  ts_88.asc   ts_96a.asc  tse_8.asc  tss_8.asc
gs_4.asc     ts_105.asc   ts_18.asc   ts_31.asc  ts_46.asc  ts_5.asc   ts_74.asc  ts_89a.asc  ts_96.asc   tse_9.asc  tss_9.asc
gs_5.asc     ts_10a.asc   ts_19.asc   ts_32.asc  ts_47.asc  ts_60.asc  ts_75.asc  ts_89.asc   ts_97a.asc  tsn_1.asc  tsw_1.asc
gs_6.asc     ts_10.asc    ts_1a.asc   ts_33.asc  ts_48.asc  ts_61.asc  ts_76.asc  ts_8a.asc   ts_97.asc   tsn_2.asc  tsw_2.asc
gs_7.asc     ts_11a.asc   ts_1.asc    ts_34.asc  ts_49.asc  ts_62.asc  ts_77.asc  ts_8.asc    ts_98a.asc  tsn_3.asc  tsw_3.asc
gs_8.asc     ts_11.asc    ts_20.asc   ts_35.asc  ts_4a.asc  ts_63.asc  ts_78.asc  ts_90a.asc  ts_98.asc   tsn_4.asc  tsw_4.asc
gs_9.asc     ts_12a.asc   ts_21.asc   ts_36.asc  ts_4.asc   ts_64.asc  ts_79.asc  ts_90.asc   ts_99a.asc  tsn_5.asc  tsw_5.asc
ts_100a.asc  ts_12.asc    ts_22.asc   ts_37.asc  ts_50.asc  ts_65.asc  ts_7a.asc  ts_91a.asc  ts_99.asc   tsn_6.asc  tsw_6.asc
ts_100.asc   ts_13a.asc   ts_23.asc   ts_38.asc  ts_51.asc  ts_66.asc  ts_7.asc   ts_91.asc   ts_9a.asc   tsn_7.asc  tsw_7.asc
ts_101a.asc  ts_13.asc    ts_24.asc   ts_39.asc  ts_52.asc  ts_67.asc  ts_80.asc  ts_92a.asc  ts_9.asc    tsn_8.asc  tsw_8.asc
ts_101.asc   ts_14a.asc   ts_25.asc   ts_3a.asc  ts_53.asc  ts_68.asc  ts_81.asc  ts_92.asc   tse_1.asc   tsn_9.asc  tsw_9.asc
ts_102a.asc  ts_14.asc    ts_26.asc   ts_3.asc   ts_54.asc  ts_69.asc  ts_82.asc  ts_93a.asc  tse_2.asc   tss_2.asc
ts_102.asc   ts_15a.asc   ts_27.asc   ts_40.asc  ts_55.asc  ts_6a.asc  ts_83.asc  ts_93.asc   tse_3.asc   tss_3.asc
ts_103a.asc  ts_15.asc    ts_28.asc   ts_41.asc  ts_56.asc  ts_6.asc   ts_84.asc  ts_94a.asc  tse_4.asc   tss_4.asc
ts_103.asc   ts_16a.asc   ts_29.asc   ts_42.asc  ts_57.asc  ts_70.asc  ts_85.asc  ts_94.asc   tse_5.asc   tss_5.asc

# 11  
Old 01-28-2013
Quote:
Originally Posted by nex_asp
here is list of one of my files in one folder for which I am trying...

Code:
gs_10.asc    ts_104a.asc  ts_16.asc   ts_2a.asc  ts_43.asc  ts_58.asc  ts_71.asc  ts_86.asc   ts_95a.asc  tse_6.asc  tss_6.asc
gs_2.asc     ts_104.asc   ts_17a.asc  ts_2.asc   ts_44.asc  ts_59.asc  ts_72.asc  ts_87.asc   ts_95.asc   tse_7.asc  tss_7.asc
gs_3.asc     ts_105a.asc  ts_17.asc   ts_30.asc  ts_45.asc  ts_5a.asc  ts_73.asc  ts_88.asc   ts_96a.asc  tse_8.asc  tss_8.asc
gs_4.asc     ts_105.asc   ts_18.asc   ts_31.asc  ts_46.asc  ts_5.asc   ts_74.asc  ts_89a.asc  ts_96.asc   tse_9.asc  tss_9.asc
gs_5.asc     ts_10a.asc   ts_19.asc   ts_32.asc  ts_47.asc  ts_60.asc  ts_75.asc  ts_89.asc   ts_97a.asc  tsn_1.asc  tsw_1.asc
gs_6.asc     ts_10.asc    ts_1a.asc   ts_33.asc  ts_48.asc  ts_61.asc  ts_76.asc  ts_8a.asc   ts_97.asc   tsn_2.asc  tsw_2.asc
gs_7.asc     ts_11a.asc   ts_1.asc    ts_34.asc  ts_49.asc  ts_62.asc  ts_77.asc  ts_8.asc    ts_98a.asc  tsn_3.asc  tsw_3.asc
gs_8.asc     ts_11.asc    ts_20.asc   ts_35.asc  ts_4a.asc  ts_63.asc  ts_78.asc  ts_90a.asc  ts_98.asc   tsn_4.asc  tsw_4.asc
gs_9.asc     ts_12a.asc   ts_21.asc   ts_36.asc  ts_4.asc   ts_64.asc  ts_79.asc  ts_90.asc   ts_99a.asc  tsn_5.asc  tsw_5.asc
ts_100a.asc  ts_12.asc    ts_22.asc   ts_37.asc  ts_50.asc  ts_65.asc  ts_7a.asc  ts_91a.asc  ts_99.asc   tsn_6.asc  tsw_6.asc
ts_100.asc   ts_13a.asc   ts_23.asc   ts_38.asc  ts_51.asc  ts_66.asc  ts_7.asc   ts_91.asc   ts_9a.asc   tsn_7.asc  tsw_7.asc
ts_101a.asc  ts_13.asc    ts_24.asc   ts_39.asc  ts_52.asc  ts_67.asc  ts_80.asc  ts_92a.asc  ts_9.asc    tsn_8.asc  tsw_8.asc
ts_101.asc   ts_14a.asc   ts_25.asc   ts_3a.asc  ts_53.asc  ts_68.asc  ts_81.asc  ts_92.asc   tse_1.asc   tsn_9.asc  tsw_9.asc
ts_102a.asc  ts_14.asc    ts_26.asc   ts_3.asc   ts_54.asc  ts_69.asc  ts_82.asc  ts_93a.asc  tse_2.asc   tss_2.asc
ts_102.asc   ts_15a.asc   ts_27.asc   ts_40.asc  ts_55.asc  ts_6a.asc  ts_83.asc  ts_93.asc   tse_3.asc   tss_3.asc
ts_103a.asc  ts_15.asc    ts_28.asc   ts_41.asc  ts_56.asc  ts_6.asc   ts_84.asc  ts_94a.asc  tse_4.asc   tss_4.asc
ts_103.asc   ts_16a.asc   ts_29.asc   ts_42.asc  ts_57.asc  ts_70.asc  ts_85.asc  ts_94.asc   tse_5.asc   tss_5.asc

Check Your below command you should use _ there Smilie
Quote:
Originally Posted by nex_asp
Code:
for file in `ls *.txt |sort -t"-" -k2n,2`; do

This User Gave Thanks to pamu For This Post:
# 12  
Old 01-28-2013
Thank you so much....whether pamu its possible to convert binary file to ascii completely..in shell...
# 13  
Old 01-28-2013
Quote:
Originally Posted by nex_asp
Thank you so much....whether pamu its possible to convert binary file to ascii completely..in shell...
I am not aware of this..

this thread may help you..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Overwrite specific column in xml file with the specific column from adjacent line

I have an xml file dumped from rrd file, that I want to "patch" so the xml file doesn't contain any blank hole in the resulting graph of the rrd file. Here is the file. <!-- 2015-10-12 14:00:00 WIB / 1444633200 --> <row><v> 4.0419731265e+07 </v><v> 4.5045912770e+06... (2 Replies)
Discussion started by: rk4k
2 Replies

2. Shell Programming and Scripting

To read specific line from a file

Hi, I have a ldif file like below: version: 1 dn: cn=Test Group,ou=Applications,dc=xyz,dc=com objectClass: groupOfUniqueNames objectClass: top cn: Test Group uniqueMember: uid=abc,ou=People,o=xyz,o=Corporate,dc=xyz,dc=com dn: cn=Test Sub Group,cn=Test... (4 Replies)
Discussion started by: saurau
4 Replies

3. Shell Programming and Scripting

How to grep an empty line in a specific column of a file?

Suppose i have the following data : cat file.txt 12431,123334,55353,546646,14342234,4646,35234 123123,3535,123434,132535,1234134,13535,123534 123213,545465,23434,45646,2342345,4656,31243 2355425,2134324,53425,342,35235,23434,234535 3423424,234234,65465,,2344,35436,234524,234... (7 Replies)
Discussion started by: Ravi Tej
7 Replies

4. Shell Programming and Scripting

Read file from nth line to specific character

Hi, I want to read the file from nth line (where n is an integer) to until I encounter @ char. Can any one please help me how to do this? Thanks. (3 Replies)
Discussion started by: laalesh
3 Replies

5. Shell Programming and Scripting

how read specific line in a file and write it in a new text file?

I have list of files in a directory 'dir'. Each file is of type HTML. I need to read each file and get the string which starts with 'http' and write them in a new text file. How can i do this shell scripting? file1.html <head> <url>http://www.google.com</url> </head> file2.html <head>... (6 Replies)
Discussion started by: vel4ever
6 Replies

6. Shell Programming and Scripting

read file line by line print column wise

I have a .csv file which is seperated with (;) inputfile --------- ZZZZ;AAAA;BBB;CCCC;DDD;EEE; YYYY;BBBB;CCC;DDDD;EEE;FFF; ... ... reading file line by line till end of file. while reading each line output format should be . i need to print only specific columns let say 5th... (2 Replies)
Discussion started by: rocking77
2 Replies

7. Shell Programming and Scripting

How to read the value from a specific line and column BASH

Hi All, I have the same problem as the one posted in https://www.unix.com/shell-programming-scripting/96097-how-read-value-specific-line-column-csh-variable.html but I'm using bash. Can anyone tell me how I have to modify the code to make it bash compatible? eval `awk 'NR==3{print "set... (5 Replies)
Discussion started by: f_o_555
5 Replies

8. Shell Programming and Scripting

A script that read specific fileds from the 7th line in a file

Dear All, I need a unix script that will read the 7th line and especially these fileds from a file Mo speed 16, Mt speed 15 every 15 minutes starting from 00:00 to 23:45 on daily basis and put the result in a txt file and name it MT_MO_20090225.txt, please also note that the system date format... (2 Replies)
Discussion started by: samura
2 Replies

9. Shell Programming and Scripting

How to read the value from a specific line and column in to a csh variable

Hi All, Although its a basic question the last 2 hours of googling and trying didnt help me to achieve what i want. Maybe some one can help me I have a text file text1.txt: blablablabla A B C D E F and i would like to read to read what is on position E (line 3 column 2) in a... (2 Replies)
Discussion started by: Radamez
2 Replies

10. UNIX for Dummies Questions & Answers

Retrieve line from a file based on a value in specific column

Hi, I have a file that has several values seperated by ":" 2006:John:Student:Football:Portugal:Cinema 2006:James:Engineer:Basket:Poland:Theatre 2007:Lucy:Diver:Gymnastic:England:Music 2007:Smith:Plumber:Basket:Spain:Poker I need make a filter based on the 5th field to find countries that... (1 Reply)
Discussion started by: efernandes
1 Replies
Login or Register to Ask a Question