Help printing string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help printing string
# 1  
Old 01-22-2014
Help printing string

Hi,

I have a file containing many times the word "IPaddress". and i need a command that finds that string or word and print it only once. I've tried the following but they print a line for each match:

Code:
grep "IPaddress" /directory/file.xml
find . | xargs grep 'IPaddress' -sl

i have many others but i get the same results.
# 2  
Old 01-22-2014
Having trouble understanding what you want, here are a couple of examples

This should print out the path of any file containing your string, note I used -type f to avoid looking at directories or special files and the -print0 and -0 args are to support files/directories with spaces -r stops grep being run if no files exist under path (ie find did not match any files):

Code:
find . -type f -print0 | xargs -0 -r grep -l 'IPaddress'

This will print "IPaddress" if the given file contains the string
Code:
grep -q "IPaddress" /directory/file.xml && echo "IPaddress"

# 3  
Old 01-23-2014
As Chubler_XL said, your requirement doesn't seem very clear.

If you wanted to print the contents of the first matching line from a file you could do:
Code:
 awk '/IPaddress/ {print; exit}' file

Or if you have GNU grep:
Code:
grep -m1 IPaddress file

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing the lines of the string with highest value

Please help . The script need to first grep for all lines with "C:" as it contains a value Here the value is 0 1,00: This , is a good script c:0 and then give output of the lines with top 3 highest value for c: 1,00: This , is a nice script c:9999 1,00: This , is a... (3 Replies)
Discussion started by: necro98
3 Replies

2. Programming

Printing same strIng many times

In python how we need to print a same string many times without using loop. I cane across something like * operator for this . How we Can use this in a print statement ? I am using python 3.x Please help me (7 Replies)
Discussion started by: pandeesh
7 Replies

3. Shell Programming and Scripting

grep on string and printing line after until another string has been found

Hello Everyone, I just started scripting this week. I have no background in programming or scripting. I'm working on a script to grep for a variable in a log file Heres what the log file looks like. The x's are all random clutter xxxxxxxxxxxxxxxxxxxxx START: xxxxxxxxxxxx... (7 Replies)
Discussion started by: rxc23816
7 Replies

4. Shell Programming and Scripting

printing lines to a file from a particular string

Hi, A very Good Evening to All, I am writing a script for my application. I have a file with 1000 lines. Among that 1000 lines i am searching for a particular string. And from that string i need to pull all the data in to a seperate file. For example the contents of my file is as below. ... (4 Replies)
Discussion started by: intiraju
4 Replies

5. Shell Programming and Scripting

Help with finding a string and printing value in the next column

Hi, been about 10 years since I've scripted, so very rusty and could use some quick help. I have a file that contains data like such: folder1 jondoe owner janedoe reader joeshmo none folder2 jondoe none janedoe none joeshmo owner folder3 jondoe owner folder4 janedoe owner joeshmo... (7 Replies)
Discussion started by: drewpark
7 Replies

6. Shell Programming and Scripting

Printing the lines which proceeds the particular string

Hi, We are facing some issues while finding the particular string. Our file is: cat 1.txt Node Name(s) Preparation fragment Partition: Transformation instance: Transformation: Applied rows: Affected rows: Rejected rows: Throughput(Rows/Sec): Throughput(Bytes/Sec): Last... (3 Replies)
Discussion started by: Amey Joshi
3 Replies

7. UNIX for Dummies Questions & Answers

Printing a part of a string

hi I have the input as follows ABC =893 JKL = "jee" alias PQR = 9833 alias STUVE = "kuiue" I should be able to print as follows ABC JKL alias PQR alias STUVE Thanks Suresh (7 Replies)
Discussion started by: ssuresh1999
7 Replies

8. UNIX for Dummies Questions & Answers

Perl, printing a string into columns

How can I use Perl to a take a string of 10 characters and print the last five characters of the string in columns 1-5 and the first five in columns 6-10? Result: 0123456789 5 0 6 1 7 2 8 3 9 4 (5 Replies)
Discussion started by: doubleminus
5 Replies

9. Shell Programming and Scripting

awk string printing

I am trying to print a line using awk printf command. The problem I am having is that when the string has spaces in between, it only prints the word upto the first space. For example, if my variable has "Hello World" The output is only "Hello". Here is the command I am using echo $recCtr... (2 Replies)
Discussion started by: fastgoon
2 Replies
Login or Register to Ask a Question