Open variable conatin name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Open variable conatin name
# 1  
Old 02-08-2013
Open variable conatin name

hi All,

I have a variable c which collects logs path name like "xyz.date.log".
Now with that Path name i want to open (cat) the file in log directory and then grep for word like bytes then awk for $6 .
Code:
cd /log/

Code:
D=`cat $C |grep -i wrote |awk 'print $6;}'


does it makes any sense ..Smilie btw its not gv any output.
# 2  
Old 02-08-2013
Quote:
Originally Posted by netdbaind;302768083[CODE
D=`cat $C |grep -i wrote |awk 'print $6;}'[/CODE]
that's useless use of cat and you have done many mistakes above.
try sth like this..

Code:
D=$(grep -i wrote $C | awk '{print $6}')

# 3  
Old 02-08-2013
Thanks for Reply Pamuand correction also .

no o/p gettng with this code.

c has only the file name xyz.date.log we need to more or cat /log/xyz.date.log and then grep and awk.

---------- Post updated at 02:50 AM ---------- Previous update was at 02:48 AM ----------

sorry for typo.

*Thanks for Reply PAMU and for correction also.
# 4  
Old 02-08-2013
You could do this in one sweep with awk:
Code:
$ D=$(awk '/[wW][rR][oO][tT][eE]/ {print $6}'  "$c")
or
$ D=$(awk 'toupper($0) ~ /WROTE/ {print $6}'  "$c")

# 5  
Old 02-08-2013
Code:
D=$(awk 'tolower($0) ~ /wrote/ {print $6}'  "$C")

Edit: See that RudiC posted nearly the same.
# 6  
Old 02-08-2013
Rudic,

code hanged it seems...no o/p Smilie
# 7  
Old 02-08-2013
- does your file contain the string "wrote" in any combination of upper/lower case?
- does $c translate to that file? (I see the other contributors have $C - you used a lower case c in your post#1.) Try replacing $c with $C.
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Vim help.txt automatically open every time I open vi

Hi Friends, Every I try to open a vi window, vim help.txt automatically opens evertime. After doing ZZ or :q! also the same page opens automatically. How to stop this? Is it machine specific ? Other users who are opening the same servers and files are not facing this issue. Thanks... (3 Replies)
Discussion started by: sudiptabhaskar
3 Replies

2. UNIX for Beginners Questions & Answers

Vim help.txt automatically open every time I open vi

Hi Friends, Every I try to open a vi window vim help.txt automatically opens evertime. After doing ZZ or :q! also the same page opens automatically. How to stop this? Is it machine specific ? Other users who are opening the same servers and files are not facing this issue. Thanks... (1 Reply)
Discussion started by: sudiptabhaskar
1 Replies

3. Shell Programming and Scripting

Open the file and replace the variable with actual value

Hi, i have a sql file named sample.sql. The query is given below. select count(*) from $TABLE_NAME In the main script, i am sourcing this sql. I need to replace the $TABLE_NAME with actual value, before running the query. How can i achieve that? The logic i tried is given below:... (3 Replies)
Discussion started by: bharathappriyan
3 Replies

4. Shell Programming and Scripting

parsing data from xml file is failing can't open variable

Created a korn shell script, everything is is working except this section, the variable $SYSINFO is being set, but the NASIP & NASDEV are failing, it appears to be treating the config.xml file config directory and xml as the file. Need a second set of eyes to tell me where I am messing up. #... (3 Replies)
Discussion started by: juanb25
3 Replies

5. Red Hat

cannot set user id: Resource temporarily unavailable (not open file/open process related)

First post, sorry to be a bother but this one has been dogging me. I have a process user (java application server) that trips a resource limit every couple weeks and need help finding what limit we're hitting. First, this is what's running: This is the error when jobs are run or the... (0 Replies)
Discussion started by: Katahdin
0 Replies

6. Shell Programming and Scripting

Performing an open/read, open/write

I'm trying to do two different things (converting an OpenVms .com to a ksh shell script): 1) open/read/err= 2) open/write/err= Any help? I've found some things, but can't seem to find the correct way. (1 Reply)
Discussion started by: prosserj
1 Replies
Login or Register to Ask a Question