Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hai
I have a txt file with several numbers and characters separated by both the space and tabs. I have to select a line starting with one character in that line i have to look for numbers below say 3000, beyond which the entire line has to be deleted till it reaches the next line. can somebody help please.
Hai
I have a txt file with several numbers and characters separated by both the space and tabs. I have to select a line starting with one character in that line i have to look for numbers below say 3000, beyond which the entire line has to be deleted till it reaches the next line. can somebody help please.
awk, grep, cut, sed are typically the commands you would use. Your description doesn't help me understand your line structure. Can you provide a few sample lines?
the first line contains 1006 as the eighth character, I want remove all data which exceed 3000
You still haven't clearly described the problem. It looks like there are blocks of 20 or so lines, and your remark suggests that you want to filter blocks based on the eighth item of the first line of each block.
This could be done by a bash script with commands like read (to read lines), cut (to select one item from the line), a conditional statement like if [ $item -gt 3000 ], and echo (to write the lines you need to save). Put the appropriate code in a while loop to process blocks until you reach the end of the file, and inside that loop you could use another while loop to copy the desired lines to the output file until the next block is detected.
the first line contains 1006 as the eighth character, I want remove all data which exceed 3000
No, the eighth field contains 1006.
If it is greater than 3000, do you want to delete that entire line, and all lines down to the next blank line ?. Your terminology is just not logical.
yes the eighth field if it exceeds i would like to delete that line and following line till it reaches the second group. I am not expertised in writing scripts in python scripts, i am just a beginner
Last edited by kumar23kan; 10-12-2015 at 01:44 AM.
The first condition is "line starts with rd and has an 8th field greater than 3000". The corresponding action is to skip to the next line, in other words, do nothing for the current line.
The second condition is empty and matches all lines.
I have to say though, I still don't understand what you want to achieve.
Last edited by berndbausch; 10-12-2015 at 01:54 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.