How to retrieve string which does not contain '$'?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to retrieve string which does not contain '$'?
# 1  
Old 10-04-2011
How to retrieve string which does not contain '$'?

Hi,

I have a file say file1.ksh. Which has data like:
Code:
ifile $AI_SERIAL/$FILE.DAT...
ofile $AI_SERIAL/feed.dat...

My requirement is to find the count of all the lines which does not have $ after /. So i have written the code:
Code:
 
grep -w 'AI_SERIAL' file1.ksh | cut  -d '/' -f2 | grep -vc '\$'

when i run this script , it is giving me correct answer : 1

but when i do :
Code:
 export key=`
grep -w 'AI_SERIAL' file1.ksh | cut -d '/' -f2 | grep -vc '\$'`
echo $key

it is returning 0. Could you please help me in this?
Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.

Last edited by vbe; 10-04-2011 at 11:45 AM..
# 2  
Old 10-04-2011
Code:
sed -n '/\/[^\$]/p' input_file

For getting the count...
Code:
sed -n '/\/[^\$]/p' input_file | wc -l

--ahamed
# 3  
Old 10-04-2011
try with this ..
Code:
key=`grep -vc "./$." infile`
set -a $key
echo $key

# 4  
Old 10-04-2011
Code:
fgrep -v "/$" infile |wc -l

# 5  
Old 10-04-2011
Urgent: How to retrieve string which doesnot contain '$'?

I have tried :

export key=`grep -w 'AI_SERIAL' file1.ksh | cut -d '/' -f2 | grep -vc "./$."`
set -a $key
echo $key

it is returning 2 but it should return 0. Smilie

---------- Post updated at 02:36 AM ---------- Previous update was at 02:32 AM ----------

I tried:

export key=`grep -w 'AI_SERIAL' file1.ksh | cut -d '/' -f2 | fgrep -v "/$" | wc -l`

but again it is returning 2 whereas i want only the lines which does not have file name without $.

Last edited by Kamna; 10-04-2011 at 03:33 AM.. Reason: Sorry it should return 1
# 6  
Old 10-04-2011
Code:
$ cat infile
ifile $AI_SERIAL/$FILE.DAT...
ofile $AI_SERIAL/feed.dat...
$ grep -vc "./$." infile
1
$

# 7  
Old 10-04-2011
Quote:
Originally Posted by Kamna
Hi,

I have a file say file1.ksh. Which has data like:

ifile $AI_SERIAL/$FILE.DAT...
ofile $AI_SERIAL/feed.dat...


My requirement is to find the count of all the lines which does not have $ after /. So i have written the code:

grep -w 'AI_SERIAL' file1.ksh | cut -d '/' -f2 | grep -vc '\$'

when i run this script , it is giving me correct answer : 1

but when i do : export key=`
grep -w 'AI_SERIAL' file1.ksh | cut -d '/' -f2 | grep -vc '\$'`
echo $key

it is returning 0. Could you please help me in this?
Code:
export key=`grep -w 'AI_SERIAL' file1.ksh |cut -d '/' -f2|grep -vc '[$]'`

Code:
export key=$(grep -w 'AI_SERIAL' file1.ksh |cut -d '/' -f2|grep -vc '\$')

regards
ygemici
This User Gave Thanks to ygemici For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Partial retrieve

I have this in log file /var/log/maillog XXX YYY ZZZ :15214 I=:25 AAA BBB CCC I need awk/sed operation on this, so that it retrieves only the first IP. cat /var/log/maillog | sed_operation 55.66.77.88 (2 Replies)
Discussion started by: anil510
2 Replies

2. Shell Programming and Scripting

How to retrieve a number or string from file1 and redirect into file2 in perl script?

hello forum members, I am siva ,As i am new to perl scripting i looking help from forum members. i need a sample program are command for pattern matching. I have file name infile1 which some data, I need to search the particular number are string in the file which repeats n number of... (0 Replies)
Discussion started by: workforsiva
0 Replies

3. Shell Programming and Scripting

Help to retrieve data from two files matching a string

Hello Experts, I have come back to this forum after a while now, since require a better way to get my result.. My query is as below.. I have 3 files -- 1 Input file, 2 Data files .. Based on the input file, data has to be retreived matching from two files which has one common key.. For EX:... (4 Replies)
Discussion started by: shaliniyadav
4 Replies

4. Shell Programming and Scripting

Retrieve a particular value into a variable

Hi, i am writing a shell script that will execute a select query. the select query returns one specific value. Idql is used for quering in documentum... X = $ (idql <docbase> -U<username> -<pwd> -Rdqlqueryfile.dql << ! set heading off set footer off !) query in dqlqueryfile is... (0 Replies)
Discussion started by: kichu
0 Replies

5. Shell Programming and Scripting

search string in a file and retrieve 10 lines including string line

Hi Guys, I am trying to write a perl script to search a string "Name" in the file "FILE" and also want to create a new file and push the searched string Name line along with 10 lines following the same. can anyone of you please let me know how to go about it ? (8 Replies)
Discussion started by: sukrish
8 Replies

6. Shell Programming and Scripting

How to retrieve digital string using sed or awk

Hi, I have filename in the following format: YUENLONG_20070818.DMP HK_20070818_V0.DMP WANCHAI_20070820.DMP KWUNTONG_20070820_V0.DMP How to retrieve only the digital part with sed or awk and return the following format: 20070818 20070818 20070820 20070820 Thanks! Victor (3 Replies)
Discussion started by: victorcheung
3 Replies

7. Shell Programming and Scripting

retrieve string from file

hi, I have write a code to retrive data from each line of a file: sed -e '/^#/d' file.csv | awk '{ printf "TEST,%s:AUX,%s;\n", $0, "'A'"}' > pippo.txt where the input file.csv was like this: 1234 2345 2334 3344 and the output of my code is a file with: TEST,1234:AUX,A;... (7 Replies)
Discussion started by: fafo77
7 Replies

8. Shell Programming and Scripting

Retrieve string from each line in a file based on a pattern in Unix

I have a file which contains several lines. Sample content of the file is as below. OK testmessage email<test@123> NOK receivemessage email<123@test> NOK receivemessage email(123@test123) NOK receivemessage email<abc@test> i would like to know by scripting will... (10 Replies)
Discussion started by: ramasar
10 Replies

9. UNIX for Advanced & Expert Users

retrieve the file.

How will retrieve for a particular months file in UNIX say for example from January to February 2008. (1 Reply)
Discussion started by: rajesh08
1 Replies

10. Shell Programming and Scripting

how to retrieve only the Use% value from df command

when I do a df -k for a particular mount i get the result like this Filesystem 1K-blocks Used Available Use% Mounted on /dev/ 4128448 3527496 391240 91% / I need to extract the value 91 from this and use it in my script in an if condition. How will i do it Please advice. (8 Replies)
Discussion started by: codeman007
8 Replies
Login or Register to Ask a Question