extract the lines by index number


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting extract the lines by index number
# 1  
Old 10-28-2011
extract the lines by index number

Hi All,

I want to extract the lines from file1 by using the index numbers from file2. In example,

Code:
 
cat file1.txt 
 
265 ABC 956  ...
698 DFA 456  ...
456 DDD 145 ...
125 DSG 154 ...
459 CGB 156 ...
490 ASF 456 ...
484 XFH 489 ...
679 hgt 481 ...
111 dfg 986 ...
356 vhn 444 ...
878 fth 256 ...
356 fgf 468 ...
489 fsr 480 ...
369 dgd 456 ...
...

Code:
 
cat file2.txt
 
3, 9, 12, ...

So, the output.txt file will be

Code:
 
cat output.txt
 
456 DDD 145 ...
111 dfg 986 ...
356 fgf 468 ...
...

Thanks in advance,
# 2  
Old 10-28-2011
What have you tried so far and where exactly are you stuck?
# 3  
Old 10-28-2011
Does file2.txt have just one line having value separated by comma? or are they in multiple line?

--ahamed
# 4  
Old 10-28-2011
file2.txt is just only 1 line.
# 5  
Old 10-28-2011
Quote:
Originally Posted by senayasma
file2.txt is just only 1 line.
Once again - please show the effort. Show exactly where you're stuck!
How is this current thread different from your old thread?
# 6  
Old 10-28-2011
Isn't this also the "negation" of this thread (or TGIF and time for me to stop looking...)?
https://www.unix.com/shell-programmin...ing-file2.html
In which case it is not a big effort to figure out what is to be modified...
# 7  
Old 10-28-2011
Hi vgersh99,

Thanks for reminding my old thread. Actually, i do not know how i can see only the threads posted by me. So, i lost it. Now, i see the solution.

I appreciate your reminding.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Substitute string with an index number

Objective is to substitute Jan with 01, Feb with 02 and so on. The month will be provided as input. I could construct below awk and it worked. echo Jun | \ awk 'BEGIN{split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec",mon," ")}{ for (i=1;i<=12;i++){ if ($1==mon) printf("%02d\n",i)} }' ... (4 Replies)
Discussion started by: krishmaths
4 Replies

2. UNIX for Dummies Questions & Answers

Count Number of Alternate Index

Hello People, I have got a requirement to count the number of duplicate alternate Indexes present in a C-ISAM/IDXFORMAT(8) file. Is there any utility that can furnish this information for the file? I am in need of the Alternate Index value and the number of times it appears as Alternate... (3 Replies)
Discussion started by: sriky86
3 Replies

3. Shell Programming and Scripting

awk extract certain digits from file with index substr

I would like to extract a digit from $0 starting 2,30 to 3,99 or 2.30 to 3.99 Can somebody fix this? awk --re-interval '{if($0 ~ /{1}{2}/) {print FILENAME, substr($0,index($0,/{1}{2}/) , 4)}}'input abcdefg sdlfkj 3,29 g. lasdfj alsdfjasl 2.86 gr. slkjds sldkd lskdjfsl sdfkj kdjlksj 3,34 g... (4 Replies)
Discussion started by: sdf
4 Replies

4. UNIX for Dummies Questions & Answers

Extract n number of lines from a file successively

Hello, I have a file with over 100,000 lines. I would like to be able extract 5000 lines at a time and give it as an input to another program. sed -n '1,5000p' <myfile> > myOut Similarly for 5001-10000 10001-15000 .... How can I do this in a loop? Thanks, Guss (5 Replies)
Discussion started by: Gussifinknottle
5 Replies

5. Shell Programming and Scripting

Extract urls from index.html downloaded using wget

Hi, I need to basically get a list of all the tarballs located at uri I am currently doing a wget on urito get the index.html page Now this index page contains the list of uris that I want to use in my bash script. can someone please guide me ,. I am new to Linux and shell scripting. ... (5 Replies)
Discussion started by: mnanavati
5 Replies

6. Emergency UNIX and Linux Support

Urgent help pls.how to extract two lines having same starting number

Hi , I have a huge file like this =245 this is testing =035 abc123 =245 this is testing1 =035 abc124 =245 this is testing2 =035 abc125 =035 abc126 =245 this is testing3 here i have to pull out those lines having two =035 instead of alternative 035 and 245 i.e extract... (18 Replies)
Discussion started by: umapearl
18 Replies

7. Shell Programming and Scripting

Awk to extract lines with a defined number of characters

This is my problem, my file (file A) contains the following information: Now, I would like to create a file (file B) containing only the lines with 10 or more characters but less than 20 with their corresponding ID: Then, I need to compare the entries and determine their frequency. Thus, I... (7 Replies)
Discussion started by: Xterra
7 Replies

8. Shell Programming and Scripting

extract the lines between specific line number from a text file

Hi I want to extract certain text between two line numbers like 23234234324 and 54446655567567 How do I do this with a simple sed or awk command? Thank you. ---------- Post updated at 06:16 PM ---------- Previous update was at 05:55 PM ---------- found it: sed -n '#1,#2p'... (1 Reply)
Discussion started by: return_user
1 Replies

9. Shell Programming and Scripting

Using Awk in shell script to extract an index of a substring from a parent string

Hi All, I am new to this shell scripting world. Struck up with a problem, can anyone of you please pull me out of this. Requirement : Need to get the index of a substring from a parent string Eg : index("Sandy","dy") should return 4 or 3. My Approach : I used Awk function index to... (2 Replies)
Discussion started by: sandeepms17
2 Replies

10. UNIX for Dummies Questions & Answers

need help getting console driver number(index)

Well, i have a little problem here. I am given device "console" of symbolical type. I do need to get its driver's number (index ?) Your help would be greatly appreciated thx, axujet (1 Reply)
Discussion started by: axujet
1 Replies
Login or Register to Ask a Question