Grep : Filter/Move All The Lines Containing Not More Than One "X" Character Into A Text File


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Grep : Filter/Move All The Lines Containing Not More Than One "X" Character Into A Text File
# 8  
Old 02-10-2015
Wow that is one solid command!

Thank you so much!

So that will grab only lines that has "x" AND only one "x" in it.

But if I want any line except repeated "x" as in more than one "x", it shall be:

Code:
cd .path;for file in *.txt;do grep -v "x.*x" "$file" > /output/directory/"$file";done

Is that correct sir?

I had just tried the command and it's super SOLID Smilie This is like the best day of my life using Terminal. More and more I am addicted to Terminal Smilie
# 9  
Old 02-10-2015
Quote:
Originally Posted by Nexeu
Wow that is one solid command!

Thank you so much!
You're welcome.
Quote:
So that will grab only lines that has "x" AND only one "x" in it.
Yes.
Quote:
But if I want any line except repeated "x" as in more than one "x", it shall be:

Code:
cd .path;for file in *.txt;do grep -v "x.*x" "$file" > /output/directory/"$file";done

Is that correct sir?
Yes; it skips over any line with two or more "x"s and copies lines with no more than one "x".
Quote:
I had just tried the command and it's super SOLID Smilie This is like the best day of my life using Terminal. More and more I am addicted to Terminal Smilie
This User Gave Thanks to Don Cragun For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Grep all lines with the string "TNS-" but skip those with "TNS-12514"

Platform: Oracle Linux 6.3 From a log file, I want to grep all lines with the pattern "TNS-" but I want to skip those with the pattern "TNS-12514" . How can I do this ? (3 Replies)
Discussion started by: John K
3 Replies

3. Shell Programming and Scripting

Filter file by length, looking only at lines that don't begin with ">"

I have a file that stores data in pairs of lines, following this format: line 1: header (preceded by ">") line 2: sequence Example.txt: >seq1 name GATTGATGTTTGAGTTTTGGTTTTT >seq2 name TTTTCTTC I want to filter out the sequences and corresponding headers for all sequences that are less... (2 Replies)
Discussion started by: pathunkathunk
2 Replies

4. Shell Programming and Scripting

Using sed to find text between a "string " and character ","

Hello everyone Sorry I have to add another sed question. I am searching a log file and need only the first 2 occurances of text which comes after (note the space) "string " and before a ",". I have tried sed -n 's/.*string \(*\),.*/\1/p' filewith some, but limited success. This gives out all... (10 Replies)
Discussion started by: haggismn
10 Replies

5. Shell Programming and Scripting

Adding a "|" character for a text file

Dear Sir, I am having text file with no delimiter like below RAGAV S S 12358 SALES EXECUTIVE 25000 RAJU R B 64253 SALES EXECUTIVE 28000 RUKMAN S 32588 SALES EXECUTIVE 40000 NARGUND S S 12356 ... (3 Replies)
Discussion started by: suryanarayana
3 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Shell Programming and Scripting

ps -ef | grep "string1" "string2" " "string3"

Hi all, can any one suggest me the script to grep multiple strings from ps -ef pls correct the below script . its not working/ i want to print OK if all the below process are running in my solaris system. else i want to print NOT OK. bash-3.00$ ps -ef | grep blu lscpusr 48 42 ... (11 Replies)
Discussion started by: steve2216
11 Replies

8. Shell Programming and Scripting

Appending character "0" in vi editor for all lines between 1 and 40.

I have to append character "0" for lines between 1 and 40 in a file. I tried the following code. :s/^0,1,40/g Input: Output: (2 Replies)
Discussion started by: pinnacle
2 Replies

9. Shell Programming and Scripting

How to print range of lines using sed when pattern has special character "["

Hi, My input has much more lines, but few of them are below pin(IDF) { direction : input; drc_pinsigtype : signal; pin(SELDIV6) { direction : input; drc_pinsigtype : ... (3 Replies)
Discussion started by: nehashine
3 Replies

10. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question