Search for text in files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search for text in files
# 1  
Old 08-24-2018
Search for text in files

I am working on a script to search for text.

Code:
read -p "Enter text to search for : " n1
grep $n1 /home/andy/bin/*.sh

It works, but if I backspace, it does this.

Code:
Enter text to search for : sset Master^[[D^[[D

------ Post updated at 12:39 PM ------

My mistake is I used the left arrow key instead of backspace. :-)
# 2  
Old 08-24-2018
Two points:
Code:
# double quotes around the pattern - it has spaces
# use frgrep rather than grep to suppress punctuation being misinterpreted as a regex
fgrep "$n1" files*

As to your question: are you on linux using bash? If so readline (not a command, it is a library bash uses) would suppress the garbage. Which can also be due to your terminal settings and your locale as well.

Code:
stty -a

will show your terminal settings.
# 3  
Old 08-24-2018
Yes, I am using bash.

What is this showing me?

Code:
stty -a
speed 38400 baud; rows 33; columns 136; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z;
rprnt = ^R; werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke -flusho -extproc

# 4  
Old 08-25-2018
I used to play with those back more than 25 years ago when we still had true "dumb" terminal connected to unix servers ( like HP9000s and using multiplexers/muliport RS232 with HP 7XX terminals/consoles ) the speed shows the speed you terminal emulates then you have the sequences that are sent back by your keyboard and what they are affected to etc....
You will still find some of them in your .profile e.g. for setting your erase key:
Code:
stty erase = ^? 
or
stty erase = ^H

# 5  
Old 08-25-2018
The good ole days.

I remember paying around $200 for a 9600 baud modem.

And use it to connect to bulletin board systems or BBSes. :-)


Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Keyword search/replace for two text files?

What is the best way (bash/awk/sed?) to read in two text files and do a keyword search/replace? file1.txt: San Francisco Los Angeles Seattle Dallas file2.txt: I love Los Angeles. Coming to Dallas was the right choice. San Francisco is fun. Go to Seattle in the summer. ... (3 Replies)
Discussion started by: pxalpine
3 Replies

2. Linux

Search only text files with 'find' command?

I've been using this to search an entire directory recursively for a specific phrase in my code (html, css, php, javascript, etc.): find dir_name -type f -exec grep -l "phrase" {} \; The problem is that it searches ALL files in the directory 'dir_name', even binary ones such as large JPEG... (2 Replies)
Discussion started by: Collider
2 Replies

3. Shell Programming and Scripting

Search and replace text in many files

Hello, I am very new to Linux and am trying to find a way for following problem. I have a number of files in a folder as Export000.dat, Export001.dat ..and so on. Each file has a string field 'Absolute velocity'. I want it to be replaced by 'Pixel shift' in all the files. I tried something like... (4 Replies)
Discussion started by: chirag.joshi
4 Replies

4. UNIX for Advanced & Expert Users

Best way to search for patterns in huge text files

I have the following situation: a text file with 50000 string patterns: abc2344536 gvk6575556 klo6575556 .... and 3 text files each with more than 1 million lines: ... 000000 abc2344536 46575 0000 000000 abc2344536 46575 4444 000000 abc2344555 46575 1234 ... I... (8 Replies)
Discussion started by: andy2000
8 Replies

5. UNIX for Dummies Questions & Answers

Search for a text within files in a directory

I need to search for a particular string. This string might be present in many files. The directory in which I am present has more than one subdirectories. Hence, the search should check in all the subdirectories and all the corresponding files and give a list of files which have the particular... (5 Replies)
Discussion started by: pakspan
5 Replies

6. Shell Programming and Scripting

search text in files within the subdirectory

Hello, I am trying to write a shell script to search for a pattern in the directory and show only one entry for each field, essentially I am looking to search for a pattern in a file and list that file name. (1 Reply)
Discussion started by: grajp002
1 Replies

7. Shell Programming and Scripting

search files without a specific text

Hi all, I need UNIX command that would give me all files without the string "4R" anywhere in the file. I have about a hundred files in my directory, and I need to list all files wihtout the string "4R" anywhere. Can anyone help me please? Thank you.l (4 Replies)
Discussion started by: risk_sly
4 Replies

8. Shell Programming and Scripting

how to do search and replace on text files in directory

I was google searching and found Perl as a command line utility tool This almost solves my problem: find . | xargs perl -p -i.old -e 's/oldstring/newstring/g' I think this would create a new file for every file in my directory tree. Most of my files will not contain oldstring and I... (1 Reply)
Discussion started by: siegfried
1 Replies

9. UNIX for Dummies Questions & Answers

String Search within Text Files

I have many scripts in directories and sub-directories that I would like to search for a specific string. How would I do that? (1 Reply)
Discussion started by: bggibson
1 Replies

10. UNIX for Dummies Questions & Answers

How do I search my dot files for suspicious text?

My company Unix guru enabled fortune in my .login (dot login?) file. When i asked him how he did it he told me to search my dot files for "suspicious" text. He wants me to learn more about all of the dot files. (1 Reply)
Discussion started by: noobie_doo
1 Replies
Login or Register to Ask a Question