0
votes
2answers
47 views

How to search '(+1)' character substring in a string

I want to search for (+1) in a string (which is a GDG dataset name to confirm if it is a GDG) and want to get a binary answer if it has (+1) as part of the string or not. Can some one please help?
-2
votes
1answer
28 views

Implementation Logic [closed]

I have two files,which is something like this: file1 msgid "New" msgstr "" dsvhuvchvdhcvhc msgid "Old" msgstr "hsvhs" kdnvcjdbvj msgid "Bold" msgstr "" file2 dcbjdsbc msgid "New" msgstr "Alas" ...
5
votes
1answer
94 views

counting multiple patterns in a single pass with grep?

I've written a grep loop to iteratively count DNA trinucleotides within a gzipped DNA fasta file containing DNA sequences e.g. declare -a tri=(AAA AAC AAG AAT CAA .. etc) for i in ${tri[@]} do ...
0
votes
3answers
230 views

grep to extract substrings in a string

I have an output for a command as below. Heading1 I am one value. I am another value. I am third value. Heading2 I am some value. I am someother value. I am new value. Heading3 ...
2
votes
2answers
102 views

How do I check that a filename conforms to a pattern?

I'm tasked with writing a shell script which checks that a filename conforms to a specific pattern and I'm not sure how to go about it. The filename should follow a pattern which looks like: ...
5
votes
5answers
109 views

A shell script to write selected fields to a single line

I have a log file trace.log which prints the time stamp, thread name and Transaction method and transaction ID as below. 2014-01-23 15:50:41,724 [catalina-exec-35] INFO TRANSACTION getConnection ...
3
votes
1answer
84 views

Can someone clarify this Bash script

I'm learning something about Bash scripting, and I came across this example: The task is to write a Bash script that reads a file, given with the first argument, pulls out those records that have the ...
3
votes
3answers
248 views

Grep command in shell script

I've been writing a shell script which should make grep command outputs for further use. However when I pass a variable containing ~/.../multiple_dir/* to grep as input I get empty output file. ...
4
votes
4answers
348 views

How can I suppress output from grep, so that it only returns the exit status?

I have the grep command. I'm searching for a keyword from a file, but I don't want to display the match. I just want to know the exit status of the grep.
1
vote
1answer
111 views

Grep Wvdial output while it is running

I want to grep the output from wvdial while wvdial is running. Actually I want to fire a task when the modem is connected. I want to do this in the following way: grep string "IP address", if it is ...
1
vote
2answers
128 views

Count entries for each directory in tree

Say I have the following tree: root: d foo d bar /foo: d A - tmp.txt /bar: d B - tmp2.txt /foo/A: - tmp3.txt /bar/B: d = directory and - = file I need to answer the following question: which ...
1
vote
2answers
92 views

Meaning of the following linux commands

cat "$1" > /tmp/file.$$ 2>/tmp/file0.$$ grep "*" /tmp/file.$$ >/tmp/file0.$$ I understood that in the cat command, if an error occurs, the error will be shown in file0.$$ and if it ...
1
vote
2answers
120 views

mv complains about standard input in a pipeline that filters file name with grep

I'm trying to move several .avi files that have spaces in from a CD to my home folder. I've already know how to get rid of the spaces: find /media/mathscd/ | grep -L -r "*.avi" | for file in *; do ...
6
votes
3answers
98 views

generate links of pages with incrementing variable

consider the links http://unix.stackexchange.com/questions/tagged/linux?page=2&sort=newest&pagesize=15 ...
2
votes
2answers
79 views

selecting specific string in a field

I have this file: N104 F1810 N104 F3810 N104 F810 N104 F305 and a script to grep an input. Script: enter input read input cat file | grep $input when I input “810”, I get the ...
3
votes
2answers
484 views

Optimizing a shell script with long running while loop

I have written a shell script which has to do the following: Capture session commands into one file. Every individual command into separate file. Mail every individual command file content based on ...
2
votes
3answers
234 views

How to grep the last number on a line in a bash script

I have output from the smartctl -a command; one of the lines looks like this: 9 Power_On_Hours 0x0032 100 100 000 Old_age Always - 301 I've placed this into a variable (if that's the correct term) ...
-1
votes
1answer
526 views

if condition, loop in grep [closed]

Could someone please provide help for me. I tried to start writing a shell script but am getting hung up with this issue. I need to grep commands "adb shell ps" and find in it 3 processes with names: ...
1
vote
2answers
257 views

Grep a string from file

I have 5 filenames created inside a folder for one operation.The filenames are in the following format. ES_currentdate_currenttime_processid_uniqueid.log I want to read the status from the latest ...
2
votes
3answers
380 views

Very strange behavior with grep and IFS

I'm having trouble using grep, the returned results are "n-empty", I mean without the 'n' character... This is the script sample : OLDIFS=$IFS IFS="\\n" i=$(grep -ril $1 *) echo $i IFS=$OLDIFS ...
2
votes
2answers
230 views

add “#” in begining to selected lines in File

Requirement : ADD someting (i.e #) in begining of every line in file A which is grep from file B File A abcd abdc sdfg asdfa jon ram File B jon abcd grep file B from file A and add "#" ...
4
votes
4answers
437 views

Count lines matching pattern and matching previous line

I want to count the number of times that a role is successfully deleted. The problem is that one line of the log file will show that the script is about to delete the role: Prepare to remove role X ...
2
votes
2answers
421 views

Parse apache logs to exclude IP ranges

I need to look for some requests in a huge pile of apache logs. My only requirement is this: I need to only view the requests coming from any IP address that is NOT included in a list of 50 IP ranges ...
2
votes
3answers
3k views

solaris 10 + display 2 lines after match by grep?

I want to match for example: The string e1000g0 from the lltconfig -a list , and then to display the two lines after the string e1000g0 so I get only the lines: Node 0 du1a : ...
2
votes
1answer
206 views

Is it a good idea to supplement shell script with perl purely for use of regex?

I'm looking for a simple way to utilize regex in a UNIX shell script where not every system will have perl extensions built into grep. What is really helpful about perl regex here is back/forward ...
2
votes
2answers
818 views

How can I retain the console input in mplayer when reading from stdin?

I'm playing around with the command line interface of mplayer. I'd like to script it in the following way find /some/path/ -type f | grep -vif blacklist | mplayer -shuffle -playlist - where ...
3
votes
3answers
3k views

How to search and replace text in all php-files in a directory and it's subdirectories

I am looking for a shell script that recursively traverses all .php files in a directory and performs a search & replace of a particular text pattern. The search pattern is quite long ( > 5000 ...
3
votes
1answer
982 views

How to use a value returned by a script in grep filter?

I'm on FreeBSD's csh. I want to form a row with domains of one user and then use this row to filter exim maillog to get only mail from/to this user's domains. I wrote a script to form a row from a ...
3
votes
1answer
5k views

Filtering on dates with grep and awk

I have created the alias below in my .bash_aliases file alias auth="grep \"$(date|awk '{print $2,$3}')\" /var/log/auth.log | grep -E '(BREAK-IN|Invalid user|Failed|refused|su|Illegal)'" ...