cut awk dummy question :)


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers cut awk dummy question :)
# 8  
Old 11-10-2007
another question

how to make this:
let's say we have
a | b | c | d
i want whole command fail with error code if just one of them fails
or if just one of them fails then whole command error code is greater than 0
# 9  
Old 11-10-2007
The bash shell has a -o pipefail option. If pipefail is enabled, the return status is the value of the last (rightmost?) command to exit with a non-zero status, or zero if all commands exit successfully.

Quote:
Originally Posted by sopel39
how to make this:
let's say we have
a | b | c | d
i want whole command fail with error code if just one of them fails
or if just one of them fails then whole command error code is greater than 0
# 10  
Old 11-10-2007
Quote:
Originally Posted by Lakris
if I enter for example on the commandline it evaluates to three elements
Isn't that all we ask for? Consider the following:

Code:
bakunin@bookchin $ cat parse.sh
#! /bin/ksh
print - "first arg: \"$1\"  second arg: \"$2\" third arg: \"$3\""
exit 0

bakunin@bookchin $ ./parse.sh first "second argument" third
first arg: "first"  second arg: "second argument" third arg: "third"

By now the solution should be clear: read in the whole file line by line, feed it - unquoted - to a script which splits it up in the different parts and writes the result to stdout. From there we read it back in. Voilá!

PS: if there are more than 9 such items on one line use "shift" to acccess all the cmd-line parameters.

bakunin
# 11  
Old 11-10-2007
thank you very much for answers
i have only one more question
let's say my script has a child 'a' (made by 'a &' command)
i want to wait for it (using wait command) but i also want to do something else every second
how do do it?
# 12  
Old 11-11-2007
Quote:
Originally Posted by bakunin
Isn't that all we ask for? Consider the following:

Code:
bakunin@bookchin $ cat parse.sh
#! /bin/ksh
print - "first arg: \"$1\"  second arg: \"$2\" third arg: \"$3\""
exit 0

bakunin@bookchin $ ./parse.sh first "second argument" third
first arg: "first"  second arg: "second argument" third arg: "third"

By now the solution should be clear: read in the whole file line by line, feed it - unquoted - to a script which splits it up in the different parts and writes the result to stdout. From there we read it back in. Voilá!

PS: if there are more than 9 such items on one line use "shift" to acccess all the cmd-line parameters.

bakunin
Have You tried it? I couldn't get it to work that way...
Quote:
lakris@ubuntu:~/projekt/scripts$ while read line;do ./parse.sh $line;done < textfile.txt
first arg: "Male" second arg: ""adam" third arg: "jones""
first arg: ""Not" second arg: "confirmed"" third arg: ""paul"
first arg: "Female" second arg: ""kelly" third arg: "lowe""
And Yes it is what we ask for, and it works on the command line, or when the string is hard coded but not when it is passed as a variable.

Last edited by Lakris; 11-11-2007 at 10:04 AM..
# 13  
Old 11-11-2007
in what package getconf is?
in my computer it is in glibc-common
but on the server i'm testing my scipts is says that there is no glibc-common but there sill is getconf
# 14  
Old 11-12-2007
Quote:
Originally Posted by Lakris
Have You tried it? I couldn't get it to work that way...
Yes. Here is a sample script:

Code:
#! /bin/ksh

parse_it ()
{
print - "entering parse_it():"
while [ $# -gt 0 ] ; do
     print - "-- >$1<"
     shift
done
return 0
}


# main ()
# prepare input file
print - "willi \"hugo kuno\" theo" > parse.in
print - "\"first arg\" \"second\" third" >> parse.in

# parse it
cat parse.in | while read line ; do
     set -xv
     eval parse_it $line
     set +xv
done

exit 0

This works on AIX 5.3 and its implementation of ksh and on Linux (SLES 10) too. Can't say about other implementations of ksh but it *should* work.

bakunin
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Dummy Question

Where can I get UNIX? (1 Reply)
Discussion started by: ciao303
1 Replies

2. UNIX for Dummies Questions & Answers

Dummy question on awk

Hi, I have a file which has three columns and 200 rows. I would like to print an extra column say "disco" for every 10 th row starting from 4 th row. How is that possible? Thnx (4 Replies)
Discussion started by: Indra2011
4 Replies

3. IP Networking

DNS dummy question

Hello everyone, I have a some doubt about DNS. We have connected to 2 ISPs /ISP#1 and ISP#2/. Our web site's dns zone is located on ISP#1. If connection to ISP#1 is down clients won't find our website. ISP#1 connection went down few times this month. So we are going to create our website's... (0 Replies)
Discussion started by: sembii
0 Replies

4. UNIX for Dummies Questions & Answers

a dummy question on data processing

Hi, everyone, I have a matrix, let's say: 1 2 3 4 5 6 ... 4 5 6 7 8 9 ... 7 8 9 1 2 3 ... 3 4 5 6 7 8 ... ......... (nxm matrix) Is there a simple command that can take certain specific rows out of the matrix? e.g., I want to take row 2 (4 5 6 7 8 9 ...) and row 4 (3 4 5 6 7 8... (2 Replies)
Discussion started by: kaixinsjtu
2 Replies

5. UNIX for Dummies Questions & Answers

dummy question on data process

I have a file which contains 6 columns. But I only need the first 3 columns. So I need to remove the last 3 columns. I checked 'cut' but it seems not working. So is there a command that could remove certain columns from a file? :( Thanks a lot!! (5 Replies)
Discussion started by: kaixinsjtu
5 Replies

6. UNIX for Dummies Questions & Answers

a dummy question...needs help...

I am trying to use 'cut' to get a line from my file. But it seems that 'cut' recongnizes TAB as default. My file uses space instead. So 'cut' doesn't work. Anybody can tell me how to change the default from TAB to space ? Or how to transform a space-delimited file into tab-delimited file??... (2 Replies)
Discussion started by: kaixinsjtu
2 Replies

7. UNIX for Dummies Questions & Answers

Dummy question about /proc/cpuinfo

Perhaps this is a very dummy question but sorry I don't know other place to do it. We just buy a new cluster of Xeon machines but there is something I don't understand and perhaps someone can help me. The more /proc/cpuinfo produces the following output (just part of it). processor : 0... (1 Reply)
Discussion started by: jhc
1 Replies

8. Filesystems, Disks and Memory

A simple dummy question

Hello Everyone! changing from Microsoft to Macintosh, I connected my hard disk (nearly full) to the apple computer, which could not recognize it. I was prompt to "initialize it", unfortunately I DECIDED YES!!, but just for 1/100 of a second: now I cannot access the hard disk at all. Is still... (1 Reply)
Discussion started by: NETTO68
1 Replies

9. UNIX for Dummies Questions & Answers

question from a dummy

okay so I just started this unix class and understood all the test questions but this "normal" question threy me through a loop :confused:. The question is Why are UNIX commands noninteractive and why is their output not usually preceededby header information? This question has been driving me... (2 Replies)
Discussion started by: cinnamonbear
2 Replies

10. UNIX for Dummies Questions & Answers

Unix dummy's question

:confused: Hi, 2 questions to get some insight. Thanks (1) I would like to add a prefix (XX00) in each row of the line in my text file and save a newly generated file another name. How to go about it. (2) How to insert a blank line into each row in my file. and save the file another name.... (2 Replies)
Discussion started by: merry susana
2 Replies
Login or Register to Ask a Question