Remove line from file and read file line by line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Remove line from file and read file line by line
# 1  
Old 10-25-2018
Remove line from file and read file line by line

I have a file output.txt. File looks like this
Code:
name1 10
name2 2
name3 5

I get a number n and I need to remove all lines which has number (after name) smaller or equal to n number.

After that I need to write lines from file and my output must be like this:
Code:
Output: 'name1 10'
Output: 'name2 20'
Output: 'name3 5'

Thank you for your help

Last edited by Scrutinizer; 10-25-2018 at 11:47 AM.. Reason: Code Tags
# 2  
Old 10-25-2018
Quote:
Originally Posted by kubo12312
I have a file output.txt. File looks like this
Code:
name1 10
name2 2
name3 5

I get a number n and I need to remove all lines which has number (after name) smaller or equal to n number.

After that I need to write lines from file and my output must be like this:
Code:
Output: 'name1 10'
Output: 'name2 20'
Output: 'name3 5'

Thank you for your help
Welcome to The UNIX and Linux Forums.

Since the capabilities of the utilities available and the utilities available on UNIX, Linux, and similar systems vary from system to system, please always tell us what operating system you're using when you start a new thread in the Shell Programming and Scripting forum. And, since the syntax and options accepted by shells and the built-ins provided by shells vary from system to system and shell to shell, please also always tell us what shell you're using when you start a new thread in the Shell Programming and Scripting forum.

I'm confused by your requirements. You talked about getting a number n, but you didn't say anything about what value was assigned to n to get the output that you say must be produced. And, I don't see anything in your description that would cause an input line:
Code:
name2 2

to be converted to the output:
Code:
Output: 'name2 20'

Please tell us what operating system you're using, what shell you're using, how the value n is to be determined, and under what circumstances the second value on an input line is supposed to be multiplied by ten.

And show us what you have tried to solve this problem on your own. If we don't know where you're stuck, it is hard for us to guess what we need to do to help you learn how to do what you want to do.
These 2 Users Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script UNIX to read text file line by line

i have a text file as belows, it includes 2 columns, 1st is the column name, 2nd is the file_name data_file.txt column_name file_name col1 file1 col2 file2 col3 file1 col4 file1 col5 file2 now, i would like to... (4 Replies)
Discussion started by: tester111
4 Replies

2. Shell Programming and Scripting

How to read file line by line and compare subset of 1st line with 2nd?

Hi all, I have a log file say Test.log that gets updated continuously and it has data in pipe separated format. A sample log file would look like: <date1>|<data1>|<url1>|<result1> <date2>|<data2>|<url2>|<result2> <date3>|<data3>|<url3>|<result3> <date4>|<data4>|<url4>|<result4> What I... (3 Replies)
Discussion started by: pat_pramod
3 Replies

3. Shell Programming and Scripting

Bash script to read a file from particular line till required line and process

Hi All, Am trying to write wrapper shell/bash script on a utility tool for which i need to pass 2 files as arugment to execute utility tool. Wraper script am trying is to do with above metion 2 files. utility tool accepts : a. userinfo file : which contains username b. item file : which... (2 Replies)
Discussion started by: Optimus81
2 Replies

4. Shell Programming and Scripting

How to read a text file line by line and insert into a database table?

I have a test file that I want to read and insert only certain lines into the the table based on a filter. 1. Rread the log file 12 Hours back Getdate() -12 Hours 2. Extract the following information on for lines that say "DUMP is complete" A. Date B. Database Name C.... (2 Replies)
Discussion started by: JolietJake
2 Replies

5. Shell Programming and Scripting

Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line...

Hello, I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be: SRVXPAPI001 ERRO JUN24 07:28:34 1775 REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F ... (8 Replies)
Discussion started by: Ferocci
8 Replies

6. Shell Programming and Scripting

Shell script to read a text file line by line & process it...

Hi , I am trying to write an shell, which reads a text file (from a location) having a list of numbers of strictly 5 digits only ex: 33144 Now my script will check : 1) that each entry is only 5 digits & numeric only, no alphabets, & its not empty. 2)then it executes a shell script called... (8 Replies)
Discussion started by: new_to_shell
8 Replies

7. Shell Programming and Scripting

Read file line by line and process the line to generate another file

Hi, i have file which contains data as below(Only sample shown, it may contain more data similar to the one shown here) i need to read this file line by line and generate an output file like the one below i.e based on N value the number of MSISDNs will vary, if N=1 then the following... (14 Replies)
Discussion started by: aemunathan
14 Replies

8. Shell Programming and Scripting

bash: read file line by line (lines have '\0') - not full line has read???

I am using the while-loop to read a file. The file has lines with null-terminated strings (words, actually.) What I have by that reading - just a first word up to '\0'! I need to have whole string up to 'new line' - (LF, 10#10, 16#A) What I am doing wrong? #make file 'grb' with... (6 Replies)
Discussion started by: alex_5161
6 Replies

9. Shell Programming and Scripting

shell script to read a line in gps receiver log file and append that line to new file

Hi, I have gps receiver log..its giving readings .like below Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. GPSD,R=1 $GPGSV,3,1,11,08,16,328,40,11,36,127,00,28,33,283,39,20,11,165,00*71... (3 Replies)
Discussion started by: gudivada213
3 Replies
Login or Register to Ask a Question