[ask]awk in csh to extract content from file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [ask]awk in csh to extract content from file
# 8  
Old 07-28-2011
test --> inputfile

> test.var ---> redirecting the output to another file ( test.var )

&& --> executes once the previous command is success
Bash Reference Manual

Code:
 
eg: 
echo "hello" && echo "echo hello is executed successfully" || echo "echo hello failed"
echho "hello" && echo "echo hello is executed successfully" || echo "echo hello failed"

. --> means dot operator or source operator source or dot operator MAN Page
This User Gave Thanks to itkamaraj For This Post:
# 9  
Old 07-28-2011
@itkamaraj
thanks for reply

I was actually confused with the last part (in bold)
Code:
test.var && . test.var

Is it a typing mistake? coz without the bold part my code is executed successfully.

also..
Code:
echo $ani

if i write the above echo after the awk statement, i get an "undefined variable" error. Smilie
# 10  
Old 07-28-2011
seach for "source or dot operator"

Its not typing mistake.

and read about the && and || operator
This User Gave Thanks to itkamaraj For This Post:
# 11  
Old 07-28-2011
Thanks, I had never come across dot operator before.
It is available in c shell?

---------- Post updated at 12:45 PM ---------- Previous update was at 11:47 AM ----------

@itkamaraj
It seems dot operator is not available in csh or tcsh Smilie . My work is on either of both shell. can you suggest some csh/tcsh equivalent.

the problem i am facing is..i cant generate and use the variables as i wish to.


My objective is explained below:

Consider I have a simple text file as below
file1
Code:
s1 a1
s2 a2 b2
s3 a3 b3 c3

The file's content (with fixed format as above) can be added by any user.
I need to write a script to automatically generate and use following variables
s1,a1,s2,a2,b2,s3,a3,b3,c4,...

The variables list will depend on entries of file1.
# 12  
Old 07-28-2011
What is mean by dot operator not available ?
Did u go through the source command ?
Did u read the links which i provided ?
This User Gave Thanks to itkamaraj For This Post:
# 13  
Old 07-28-2011
let me show here what i am doing:

this is the code i am running

filename: nscript
Code:
#
echo "-------------------------------"

awk '{for(i=1;i<=NF;i++)printf("%s=%s\n",$i,$i)}' script_name.txt  > script_name.var && . script_name.var
###########################################################

echo "a1 is ---> $a1"
#a1 = $2
echo $a2

###########################################################

in command prompt when i type
Code:
$ bash ./nscript

i get following output
Code:
-------------------------------
a1 is ---> a1
a2

but when i type
Code:
$ csh ./nscript

I get following output
Code:
-------------------------------
/bin/.: Permission denied.
a1: Undefined variable.

since i am new to unix, am not able to understand why I am getting such error.
I googled and came across a pdf telling dot operator is not supported in csh/tcsh.
The problem, i think is that we have a code which is interpreted ok with bash, but not in csh.

---------- Post updated at 01:46 PM ---------- Previous update was at 01:37 PM ----------

also if i run the nscript with following changes
Code:
awk '{for(i=1;i<=NF;i++)printf("%s=%s\n",$i,$i)}' script_name.txt  > script_name.var && source script_name.var

i get the following results
Code:
-------------------------------
script_B_1=script_B_1: Command not found.
a1=a1: Command not found.
script_B_2=script_B_2: Command not found.
a2=a2: Command not found.
b2=b2: Command not found.
script_B_3=script_B_3: Command not found.
a3=a3: Command not found.
b3=b3: Command not found.
c3=c3: Command not found.
a1: Undefined variable.

---------- Post updated at 01:55 PM ---------- Previous update was at 01:46 PM ----------

hey.. its working, with following modifications SmilieSmilieSmilie

Code:
awk '{for(i=1;i<=NF;i++)printf("set %s=%s\n",$i,$i)}' script_name.txt  > script_name.var && source script_name.var

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract a part of variable/line content in a file

I have a variable and assigned the following values ***XYZ_201519_20150929140642_20150929140644_211_0_0_211 I need to read this variable from backward and stop read when I get first underscore (_) In this scenario I should get 211 Thanks Kris (3 Replies)
Discussion started by: mkris
3 Replies

2. Solaris

Extract content of .dump file

We have been provided a .dump file.The need is to extract the contents(may includes files and folder). ls -lZ didnt help me as Z is not a valid option. How to extract the file contents ? (7 Replies)
Discussion started by: vinil
7 Replies

3. Shell Programming and Scripting

Shell Script to Dynamically Extract file content based on Parameters from a pdf file

Hi Guru's, I am new to shell scripting. I have a unique requirement: The system generates a single pdf(/tmp/ABC.pdf) file with Invoices for Multiple Customers, the format is something like this: Page1 >> Customer 1 >>Invoice1 + invoice 2 >> Page1 end Page2 >> Customer 2 >>Invoice 3 + Invoice 4... (3 Replies)
Discussion started by: DIps
3 Replies

4. Shell Programming and Scripting

Extract Content from a file

I have an input file with contents like: ./prbru6/12030613.LOG:24514|APPL|prbru6.8269.RTUDaemon.1|?|13:49:56|12/03/06|GMT+3|?|RTUServer Error:Count of Internal Error Qty (-1) < 0, for Audit group id - 1L5XVJ6DQE36AXL, after record number,1, File: EventAuditor.cc, Line: 394|? ... (5 Replies)
Discussion started by: rkrish
5 Replies

5. Shell Programming and Scripting

perl extract content of file

I'm using Mail::Internet module, which will basically filter through email content and extract the body of the message my perl script to extract the body of the email #!/usr/bin/perl -w use Mail::Internet; @lines = <STDIN>; $mi_obj = new Mail::Internet(); ... (2 Replies)
Discussion started by: amlife
2 Replies

6. Shell Programming and Scripting

Extract XML content from a file

310439 2012-01-11 03:44:42,291 INFO PutServlet:? - Content of the Message is:="1.0" encoding="UTF-8"?><ESP_SSIA_ACC_FEED> 310440 <BATCH_ID>12345678519</BATCH_ID> 310441 <UID>3498748823</UID> 310442 <FEED_TYPE>FULL</FEED_TYPE> 310443 <MART_NAME>SSIA_DM_TRANSACTIONS</MART_NAME> 310444... (11 Replies)
Discussion started by: arukuku
11 Replies

7. Shell Programming and Scripting

Extract specific content from a file

My input file: >sequence_1 ASSSSSSSSSSSDDDDDDDDDDDCCCCCCC ASDSFDFFDFDFFWERERERERFSDFESFSFD >sequence_2 ASDFDFDFFDDFFDFDSFDSFDFSDFSDFDSFASDSADSADASD ASDFFDFDFASFASFASFAFSFFSDASFASFASFAFS >sequence_3 VEDFGSDGSDGSDGSDGSDGSDGSDG dDFSDFSDFSDFSDFSDFSDFSDFSDF SDGFDGSFDGSGSDGSDGSDGSDGSDG My... (22 Replies)
Discussion started by: patrick87
22 Replies

8. UNIX for Dummies Questions & Answers

address variable content with csh

By using a csh, I want to address a variable content whose name is/matches the content of a given other variable. i.e. set name=´sam´ set ${name}_age=´27´ So, by typing: echo ${name}_age I correctly obtain: sam_age By typing: echo $sam_age or echo ${sam_age} I correctly obtain: 27 ... (1 Reply)
Discussion started by: sobolev
1 Replies

9. Shell Programming and Scripting

Content extract of a file using awk

Hi Everyone, I have a file with the below content: File1.txt ====== ### ###==> the below table was created for testing1 purpose; ### create table 123 ( field1 date, field2 char(10) primary key(field1) ); ### ###==> the below table was created... (5 Replies)
Discussion started by: nr_shan
5 Replies

10. Shell Programming and Scripting

extract content from a file and insert to another file

please help for the following task... I have to extract the mac address & IP address from the file1: ... 0100004512EEF4 03 192.168.0.7 192.168.0.1 -1 ... 0100779hF5D212 03 192.168.0.8 192.168.0.1 -1 ... 0100789lF5D212 03 192.168.0.9 192.168.0.1 -1 ... ... change the format (addidng... (15 Replies)
Discussion started by: fredao
15 Replies
Login or Register to Ask a Question