Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Extracting lines from a text file based on another text file with line numbers Post 302742821 by evelibertine on Tuesday 11th of December 2012 03:34:19 PM
Old 12-11-2012
Extracting lines from a text file based on another text file with line numbers

Hi,

I am trying to extract lines from a text file given a text file containing line numbers to be extracted from the first file. How do I go about doing this? Thanks!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extracting data from text file based on configuration set in config file

Hi , a:) i have configuration file with pattren <Range start no>,<Range end no>,<type of records to be extracted from the data file>,<name of the file to store output> eg: myfile.confg 9899000000,9899999999,DATA,b.dat 9899000000,9899999999,SMS,a.dat b:) Stucture of my data file is... (3 Replies)
Discussion started by: suparnbector
3 Replies

2. Shell Programming and Scripting

extracting unique lines from text file

I have a file with 14million lines and I would like to extract all the unique lines from the file into another text file. For example: Contents of file1 happy sad smile happy funny sad I want to run a command against file one that only returns the unique lines (ie 1 line for happy... (3 Replies)
Discussion started by: soliberus
3 Replies

3. UNIX for Dummies Questions & Answers

Extracting rows from a text file based on the first column

I have a tab delimited text file where the first column can take on three different values : 100, 150, 250. I want to extract all the rows where the first column is 100 and put them into a separate text file and so on. This is what my text file looks like now: 100 rs3794811 0.01 0.3434... (1 Reply)
Discussion started by: evelibertine
1 Replies

4. UNIX for Dummies Questions & Answers

Extracting rows from a text file based on the first column

I have a tab delimited text file where the first column can take on three different values : 100, 150, 250. I want to extract all the rows where the first column is 100 and put them into a separate text file and so on. This is what my text file looks like now: 100 rs3794811 0.01 0.3434 100... (1 Reply)
Discussion started by: evelibertine
1 Replies

5. Shell Programming and Scripting

Extracting Multiple Lines from a Text File

Hello. I am sorry if this is a common question but through all my searching, I haven't found an answer which matches what I want to do. I am looking for a sed command that will parse through a large text file and extract lines that start with specific words (which are repeated throughout the... (4 Replies)
Discussion started by: MrDumbQuestion
4 Replies

6. UNIX for Dummies Questions & Answers

Extracting rows from a text file based on the values of two columns (given ranges)

Hi, I have a tab delimited text file with multiple columns. The second and third columns include numbers that have not been sorted. I want to extract rows where the second column includes a value between -0.01 and 0.01 (including both numbers) and the first third column includes a value between... (1 Reply)
Discussion started by: evelibertine
1 Replies

7. Shell Programming and Scripting

How to delete lines of a text file based on another text file?

I have 2 TXT files with with 8 columns in them(tab separated). First file has 2000 entries whereas 2nd file has 300 entries. The first file has ALL the lines of second file. Now I need to remove those 300 lines (which are in both files) from first file so that first file's line count become... (2 Replies)
Discussion started by: prvnrk
2 Replies

8. Shell Programming and Scripting

Extracting lines from text files in folder based on the numbers in another file

Hello, I have a file ff.txt that looks as follows *ABNA.txt 356 24 36 112 *AC24.txt 457 458 321 2 ABNA.txt and AC24.txt are the files in the folder named foo1. Based on the numbers in the ff.txt file, I want to extract the lines from the corresponding files in the foo1 folder and... (2 Replies)
Discussion started by: mohamad
2 Replies

9. Shell Programming and Scripting

Extracting values based on line-column numbers from multiple text files

Dear All, I have to solve the following problems with multiple tab-separated text file but I don't know how. Any help would be greatly appreciated. I have access to Linux mint (but not as a professional). I have multiple tab-delimited files with the following structure: file1: 1 44 2 ... (5 Replies)
Discussion started by: Bastami
5 Replies

10. Shell Programming and Scripting

Match text to lines in a file, iterate backwards until text or text substring matches, print to file

hi all, trying this using shell/bash with sed/awk/grep I have two files, one containing one column, the other containing multiple columns (comma delimited). file1.txt abc12345 def12345 ghi54321 ... file2.txt abc1,text1,texta abc,text2,textb def123,text3,textc gh,text4,textd... (6 Replies)
Discussion started by: shogun1970
6 Replies
exstr(1)							   User Commands							  exstr(1)

NAME
exstr - extract strings from source files SYNOPSIS
exstr filename... exstr -e filename... exstr -r [-d] filename... DESCRIPTION
The exstr utility is used to extract strings from C-language source files and replace them by calls to the message retrieval function (see gettxt(3C)). This utility will extract all character strings surrounded by double quotes, not just strings used as arguments to the printf command or the printf routine. In the first form, exstr finds all strings in the source files and writes them on the standard output. Each string is preceded by the source file name and a colon (:). The first step is to use exstr -e to extract a list of strings and save it in a file. Next, examine this list and determine which strings can be translated and subsequently retrieved by the message retrieval function. Then, modify this file by deleting lines that can't be translated and, for lines that can be translated, by adding the message file names and the message numbers as the fourth (msgfile) and fifth (msgnum) entries on a line. The message files named must have been created by mkmsgs(1) and exist in /usr/lib/locale/locale/LC_MES- SAGES . (The directory locale corresponds to the language in which the text strings are written; see setlocale(3C)). The message numbers used must correspond to the sequence numbers of strings in the message files. Now use this modified file as input to exstr -r to produce a new version of the original C-language source file in which the strings have been replaced by calls to the message retrieval function gettxt(). The msgfile and msgnum fields are used to construct the first argument to gettxt(). The second argument to gettxt() is printed if the message retrieval fails at run-time. This argument is the null string, unless the -d option is used. This utility cannot replace strings in all instances. For example, a static initialized character string cannot be replaced by a function call. A second example is that a string could be in a form of an escape sequence which could not be translated. In order not to break existing code, the files created by invoking exstr -e must be examined and lines containing strings not replaceable by function calls must be deleted. In some cases the code may require modifications so that strings can be extracted and replaced by calls to the message retrieval function. OPTIONS
The following options are supported: -e Extract a list of strings from the named C-language source files, with positional information. This list is produced on standard output in the following format: file:line:position:msgfile:msgnum:string file the name of a C-language source file line line number in the file position character position in the line msgfile null msgnum null string the extracted text string Normally you would redirect this output into a file. Then you would edit this file to add the values you want to use for msgfile and msgnum: msgfile the file that contains the text strings that will replace string. A file with this name must be created and installed in the appropriate place by the mkmsgs(1) utility. msgnum the sequence number of the string in msgfile. The next step is to use exstr -r to replace strings in file. -r Replace strings in a C-language source file with function calls to the message retrieval function gettxt(). -d This option is used together with the -r option. If the message retrieval fails when gettxt() is invoked at run-time, then the extracted string is printed. You would use the capability provided by exstr on an application program that needs to run in an international environment and have messages print in more than one language. exstr replaces text strings with function calls that point at strings in a message data base. The data base used depends on the run-time value of the LC_MESSAGES environment variable (see environ(5)). EXAMPLES
Example 1: The following examples show uses of exstr Assume that the file example.c contains two strings: main() { printf("This is an example "); printf("Hello world! "); } The exstr utility, invoked with the argument example.c extracts strings from the named file and prints them on the standard output. example% exstr example.c produces the following output: example.c:This is an example example.c:Hello world! The exstr utility, invoked with the -e option and the argument example.c, and redirecting output to the file example.stringsout example% exstr -e example.c > example.stringsout produces the following output in the file example.stringsout example.c:3:8:::This is an example example.c:4:8:::Hello world! You must edit example.stringsout to add the values you want to use for the msgfile and msgnum fields before these strings can be replaced by calls to the retrieval function. If UX is the name of the message file, and the numbers 1 and 2 represent the sequence number of the strings in the file, here is what example.stringsout looks like after you add this information: example.c:3:8:UX:1:This is an example example.c:4:8:UX:2:Hello world! The exstr utility can now be invoked with the -r option to replace the strings in the source file by calls to the message retrieval func- tion gettxt(). example% exstr -r example.c <example.stringsout >intlexample.c produces the following output: extern char *gettxt(); main() { printf(gettxt("UX:1", "")); printf(gettxt("UX:2", "")); } The following example: example% exstr -rd example.c <example.stringsout >intlexample.c uses the extracted strings as a second argument to gettxt(): extern char *gettxt(); main() { printf(gettxt("UX:1", "This is an example ")); printf(gettxt("UX:2", "Hello world! ")); } FILES
/usr/lib/locale/locale/LC_MESSAGES/* files created by mkmsgs(1) ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWtoo | +-----------------------------+-----------------------------+ SEE ALSO
gettxt(1), mkmsgs(1), printf(1), srchtxt(1), gettxt(3C), printf(3C), setlocale(3C), attributes(5), environ(5) DIAGNOSTICS
The error messages produced by exstr are intended to be self-explanatory. They indicate errors in the command line or format errors encoun- tered within the input file. SunOS 5.10 5 Jul 1990 exstr(1)
All times are GMT -4. The time now is 04:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy