General :: Use Grep, Cut, Or Awk To Get An IP From A File?
Feb 3, 2010I have a file which contains a line like this:SERVER=10.205.110.19 How can I cut out the IP and assign it to a variable?
View 4 RepliesI have a file which contains a line like this:SERVER=10.205.110.19 How can I cut out the IP and assign it to a variable?
View 4 RepliesI need to kind of grep within grep. My input file would be something like:
[Code]....
and I need to find the first occurrence of hello before MY PATTERN (hello 9008 in this case), so the output should be:
[Code]....
someone once told me that use can pass a file to grep and use that to search the contents of another file. if that is the case I'm not entirely sure why the following isn't working for me.
Code:
[root@LCENT01:~]#grep -i id_rsa.pub .ssh/authorized_keys
[root@LCENT01:~]#cat id_rsa.pub >> .ssh/authorized_keys
[root@LCENT01:~]#grep -i id_rsa.pub .ssh/authorized_keys
Let me *try* and explain what I'm trying to do, and keep in mind aside from a little command line stuff I'm a beginner to any of what I'm asking about.
I have a directory structure something like this:
Code:
/usr/local/chatlogs/
webserver1/
1.chatlog
2.chatlog
[Code]....
So that whatever was captured in the () in the first part of the statement would be used in the 1 in the back part of the statement for every n.chatlog that might be in any of the /webserver directories at that time.
I have collection my routers configuration through rancid. Now i want to do the following,
Display all the files that contain the following words
C1841 AND HWIC-4ESW
I want to display all the files that contains both these words.
I'm storing a list of strings in a file and would like to read the file and pipe each line returned to grep which in turn searches a directory for files containing the string.However this is not returning any output.
View 2 Replies View RelatedI am searching for Class declaration on a site with hundreds of PHP files, how can I do this in the current folder and subfolders using GREP?
I tested cding to the folder and then something like
grep -r 'class MyClass' *.php
I have following contents
I want to grep "#2" and want the output as
How to using shell script?
I wanted to grep the line in a file starts with -1.000000e+00.
Tried grep "-1.000000e+00" *, got error "grep: invalid option --".
Neither of the following works:
grep "-1.000000e00" *
grep "1.000000e00" *
How do I grep a negative number with scientific notation?
I ran into a bit of trouble making a bash script. (Desktop is a directory, and I try to get it's modification date)
Code:
lamp:~# cmd='ls -l Desktop | grep -o "....-..-.. ..:.."'
lamp:~# $cmd
ls: cannot access |: No such file or directory
ls: cannot access grep: No such file or directory
[code]....
When I type in the command directly, without using an inbetween variable, it works fine.
I would like to write a newline delimeted rules file using PCREs for use with the grep command. Grep has the option -f to obtain the search pattern from a file, and option -P to search using PCREs. However, these two options do not work together. The -f option only seems to work with fixed string rules.A friend previously helped me get around this limitation somehow, but I can't remember how he did it. I also would like the ability to add comments at the end of each rule in the file.
View 11 Replies View RelatedI have a number of files:FooBlahhFooI only want to be able to grep for names in a file that contain Foo and not BlahhFoo. However I am not able to pull only those files away. How can this bee done. My grep/zgrep knowledge only goes this far at this point. I'm still learning but I'm stuck on how to make my arguments more precise zgrep 'Foo' SomeFileIMade.gz > /home/user/FOOFILE
View 4 Replies View RelatedI have a list of words that I want to grep in many files to see which ones have it and which ones dont. in the text file I have all the words listed line by line, ex: list.txt:
check
try this
word1
word2
open space
list ..
I want to grep each line one by one. like I want it to
grep "check" *.log
grep "try this" *.log
grep "word1" *.log .. etc how can I do this?
and maybe write the output to a file.
I am attempting to grep the contents of a key file I have SCP'd to a remote server. I am able to cat it:
Code:
[bluethundr@LBSD2:~]$:ssh root@sum1 cat /root/id_rsa.pub
root@lcent01.summitnjhome.com's password:
[code]...
I would like to grep all values other than encrypted password from /etc/shadow fileFor example,each line consists of 8 fields separated with :/The only thing that I want not to print out is the contents between first : and second : (encrypted password)
View 7 Replies View Relatedhow to update a series of values from multiple grep commands outputs to be appended to a single row of a csv file? Work on a linux envir. The values from grep output will be numeric values.
Output sold look like:
1,3,4,5,7,0,5
Each of these values will be odtained from multiple grep commands piped with wc -l Is it possible to update a single row of a csv file if so pleas ehelp me with the command to be used to redirect the output into the csv file
remove a line starting with specific word with grep. Here is what I found
grep -v '^cc$' data.txt
Here I remove all lines with on 'cc' in that line. But I want the result write back to data.txt
I try several ways
grep -v '^cc$' data.txt > output.txt # works but to another file
echo `grep -v '^cc$' data.txt` > data.txt # didn't work, all carets gone, become one line
grep -v '^cc$' data.txt > data.txt # data.txt is empty after running this
How can I save the result of grep to the input file?
To search a string pattern in all files in a directory and subdirectories, I am using;
Code:
grep -R "myclass::my-func(" mydirectory/
Now I want grep, to search in only specific file types say *.cc. Please help me. I have read manual of grep, but could not deduce any hint.
Best Regards.
I'm trying to manipulate a large text file full of records (metadata - one complete record per line). I need to delete every line on which certain words appear - there are five different words, all pretty simple all-caps strings with occasional whitespace. I tried using grep -v, which worked a treat, but only string-by-string. Ideally I'd like to run this as grep -v -f, where the file targeted by the -f contains the strings I need to match in order to delete the lines they're in.
i.e. grep -v -f filecontainingSTRINGS.txt targetfile.txt > outputfile.txt
When I try this, however, I don't get any matches - or more specifically, no changes are made in the output file. It works fine if there's only one string in filecontainingSTRINGS, but it doesn't work if there's more than one (I'm using newline as the delimiter). (Also my machine doesn't recognise /usr/xpg4/bin/grep - no idea what that's all about!)
I need to search a text file for a string of numbers which are different lengths, and always are between number=" and " like:
number="1234567890"
number="22390"
I need to grab those numbers and pipe each one to a line in a file. I've already tried something with awk and that didn't seem to work.
My script.
This is may script:
Code:
Problem: Output file doest not exclude the values in grep -av
How to find file with name="php.ini" on linux using grep command?
View 2 Replies View Relatedi have to grep a series say 98782 from a group by series in a file ,how can i grep the series.
View 6 Replies View RelatedI am trying to compare a list of patterns from one file and grep them against another file and print out only the unique patterns. Unfortunately these files are so large that they have yet to run to completion. Here's the command that I used:
Code: grep -L -f file_one.txt file_two.txt > output.output Here's some example data:
Code:
>FQ4HLCS01BMR4N
>FQ4HLCS01BZNV6
>FQ4HLCS01B40PB
>FQ4HLCS01BT43K
>FQ4HLCS01CB736
>FQ4HLCS01BU3UM
>FQ4HLCS01BBIFQ
how to increase efficiency or use another command?
I want to grep a a file for each '#' character that starts a line, the thing is the file is utf-8 and it starts with some some characters 'ef bb bf' is there a way to have grep to work with utf-8 files ?
[Code]....
i want to search some key words in some pdf files grep myword ~/test.pdf that command can't work! grep command can't search pdf file??
View 1 Replies View Relatedso i have a data file of a couple thousand lines. for example, my file will look like this (condensed of course):
Code:
something something 100 something 1 2 3
something something 101 something 4 5 6
[code]....
I am interested in using the grep method in the shell of my CentOS machine to obtain patterns from a file and use them to search through another file and highlight the patterns found. For example:
pattern file:
one
two
three
test file:
AAAAAAAAAAAAAAAAAAAAAoneAAAAAAAAAAAAAAAAthreeAAAAAAAAAAAA
I want to know that is there any method to grep a particular data from a file without using the "cat --- | grep ' ' " command....I need to use a system call for this functionality.
View 1 Replies View RelatedI want to write some code to search for a specific string in a text file, but without using grep command.
View 5 Replies View Related