1
vote
1answer
45 views

Regex works in shell but not through Perl script

I'm having trouble executing a Perl script through the Unix shell using Perl's system command. I've had more complex regex commands I had to adjust accordingly to convert from Unix to Perl, and ...
2
votes
2answers
56 views

How to get grep exit code but print all lines?

I'd like to check whether a line printed by a command contains an error message, but I'd like to also print all the output from the command (for make logs). Is there some way to get all the output of ...
0
votes
1answer
68 views

Very basic H/W question using pipe and grep

I have two text files, F1a.txt and F1b.txt, with essentially the same data: the driver's surname and their nationality. For example: Hamilton GBR Alonso SPA I have concatenated these ...
0
votes
1answer
119 views

Using Grep Colour to look in a file, and output with a coloured answer in amongst the file contents

I am currently in the process of writing a program in raspberry pi that will allow me to look inside files and have what I entered displayed in colour I think I need to do something to do with ...
1
vote
2answers
53 views

run grep cmd recursively and print path name and result

I have a log file that exists in multiple directories one for each client. I am trying to run the following: find . -iname "20140926.log" -exec cat {} \; | grep 123456 | grep 'food="100"' | wc -l ...
2
votes
2answers
62 views

redirect output of tee and grep for multiple logfiles

Redirecting output from a script STDOUT + STDERR toLogfile 1 and a grep to Logfile 2 ./run_test.sh 2>&1 | tee -a /var/log/log1.log | (grep 'START|END') > /var/log/myscripts.log How can I ...
3
votes
4answers
188 views

Test if command accepts a specific option

What is the preferred way to test if a command takes an option? What are the caveats? As a motivating example, at login my shell aliases grep to add several --exclude-dir options but this option is ...
1
vote
2answers
75 views

grep works fine in command line but returns nothing in script

I'm trying to write a small script to get me list of files that match certain criteria into a file. #!/bin/sh cd /var/www_data/patch/ grep --include=\*.{php,ini,conf,sh} -ril -P ...
4
votes
4answers
161 views

extract lines according to a particular column

I have a CSV file like CK,ck XYZ,xyz,xyzs ABC,abc,abcs PQR,pqr,pqrs LMN,lmn, IJK,ijk, I have to check if something is written in column 3 except whitespace, then display the whole line.the output ...
-1
votes
2answers
39 views

Searching out a pattern from Logs

The format of the logs is in this manner: Junk Junk Junk : Junk Junk Junk:IP/Port Junk Junk I want to search using the IP and the output should be only the IP/Port part of each line in that log ...
-3
votes
2answers
128 views

Extract certain column from CSV files [closed]

I have a directory with a group of CSV files. All files have the same column headers. I need to extract values in a certain column from all files. The common part in files names is ...
2
votes
2answers
129 views

How do you construct a grep & command to match a number of patterns depending on how many are provided at runtime?

I have exported some MS Word documents to plain text and use this function to parse the contents of the .txt files in the current directory: mo1 () { for i in *.txt; do echo "File: $i" grep ...
5
votes
1answer
632 views

Why do I have to escape a “dot” twice?

I know that we can escape a special character like *(){}$ with \ so as to be considered literals. For example \* or \$ But in case of . I have to do it twice, like \\. otherwise it is considered ...
5
votes
2answers
125 views

Is there a way to make this one-liner faster?

Context I have a directory of thousands of zip files that are dated in the form YYYYMMDD_hhmmss.zip and each about 300K. Within each zip file is about 400 xml files each about 3K. The problem I ...
2
votes
1answer
41 views

move the search content to different directory

I am on Oracle Solaris. I am using: grep "searchstring" filename.* above command returns my search result. Now I want to move the all the files in above search result (all the files not the ...
2
votes
4answers
278 views

Inserting a line in a file only if this line isn't yet part the file

Total newbie to shell scripting, I am searching to create a script to automatically apply some custom configuration to text based configuration files. In the present case, I am searching to add 2 ...
0
votes
1answer
56 views

How to output the lines of a file after find and a grep?

Hello I want to output ERROR messages from logfiles from the current date. First I search for the logs of today with specific prefix: find /home/USER/logfilesError/ -maxdepth 1 -type f -name "xy_*" ...
0
votes
2answers
40 views

How can I search filenames which are starting with xy_* and are created/edited today?

Hello I´m currently trying to search for logfiles which are starting with xy_Number and are created/edited today(not last 24 hrs). I tried: find /home/USER/logfilesError/ -maxdepth 1 -type f ...
2
votes
3answers
148 views

grep on a Java Method

Lets say I have a java class called DirectAction some of the methods in the class have the word "action" or "Action" What is the grep command to get the names of all the methods who have "Action" or ...
6
votes
10answers
1k views

Copy only Specific text of a file to another

I have a file abc.txt the contents are <classpathentry kind="src" path="Sources"/> <classpathentry kind="con" path="WOFramework/ERExtensions"/> <classpathentry kind="con" ...
2
votes
3answers
192 views

conditional coloring in grep

I have a simple bash script. One line of my script matches a "pattern" with grep and colors the match grep -i --color=always -- "$1" I need to modify it, so that it only colors the match, if the ...
1
vote
2answers
233 views

How to show specific lines from specific columns of a file

First off, I'm not allowed awk, sed or perl. For my assignment I was given a file of employee list: Marketing Ranjit Singh FULLEagles Dean Johnson Marketing Ken Whillans FULLEagles ...
0
votes
2answers
75 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
34 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
267 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
2k 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
436 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
179 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
112 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
299 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
3k 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
212 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
159 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
110 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
273 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
110 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
104 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 ...
0
votes
1answer
84 views

Problem with small bash script

I often run find in my code projects when I make a change somewhere and I have to find where it impacts other pieces of code, so I thought about writing a very small script to make this easier, call ...
3
votes
2answers
1k 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
469 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
777 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
366 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 ...
1
vote
3answers
136 views

grep for strings that were found in a previous statement

I'm trying to find out if an address definition is used inside of fortigate configuration file. I extracted the section out of the configuration file, that contains the addresses. In that section the ...
2
votes
3answers
605 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
290 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
643 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
504 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
5k 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
229 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
1k 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 ...