Sponsored Content
Full Discussion: Two curious questions
Top Forums Shell Programming and Scripting Two curious questions Post 302709647 by Corona688 on Wednesday 3rd of October 2012 11:56:55 AM
Old 10-03-2012
a) There is a limit to how much stuff you can cram in a single shell variable. On some systems, this can be as small as a screenful or so, so don't go overboard.

b) If you're doing awk | awk | sed | cut | kitchen | sink, you probably could have done that all in one awk and saved yourself a lot of bother and CPU time. You don't need to use awk twice here:

Code:
awk '{ sum += $2 } END { print sum }' inputfile

c) That's also a useless use of cat, since awk does not need cat's help to read a file. You can use it as shown above, listing the filename on the end.

To answer question 2, there's actually a few ways to set more than one variable at once. read is a particularly flexible way of doing so. It helps if you know how many are coming, though, or can convince certain ones to come first. Everything you didn't list will get crammed into the last variable you list.

Code:
read SUM NUMBERS <<EOF
`awk '{ sum += $2; A[++L]=$0 } END { print sum ; for(N=1; N<=L; N++) print A[N]}' inputfile`
EOF

I saved all the numbers in the awk array A so I could print them later. This lets me print the sum first, and then the rest, letting me pick the sum out from the front with read.

You could also do
Code:
set -- `awk '{ sum += $2; A[++L]=$0 } END { print sum ; for(N=1; N<=L; N++) print A[N]}' inputfile`

SUM=$1
shift
REST="$*"

This User Gave Thanks to Corona688 For This Post:
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Just curious, does Unix stand for anything?

If not, where did the name come from? (6 Replies)
Discussion started by: pudad
6 Replies

2. UNIX for Dummies Questions & Answers

Curious

Dear All I am curious to know, that in a system compromise, when someone has access to a box, does that individual have access to a shell on the system, i.e. the person is logging into the system using telnet or SSH to remotely access the box?? How does this individual/ hacker access the system. ... (2 Replies)
Discussion started by: skotapal
2 Replies

3. UNIX for Dummies Questions & Answers

Curious Dummy

I have a website but I do not for the life of me know how to upload using unix based command lines. Can someone send me a good site that has these commands. That and I am curious to know more about command line based interfacing. :D Curious Dummy (1 Reply)
Discussion started by: highway39
1 Replies

4. Linux

Curious?

To correct most of the problems with this language, How do I remove the DOS and WORD stuff from it? These come from the fact that it was written on those with a Microsoft supplied platform at the writers request. (1 Reply)
Discussion started by: River Freight
1 Replies

5. UNIX for Advanced & Expert Users

Curious 'ls' Issue

Hi, I am seeing a curious issue with 'ls' command. If I open a telnet session of my Solaris box and give "ls". The output is in 3 columns. a b c d e f g h i j k l However, if I give the same command after a couple of hours in the same window, it goes to 6 columns according to the... (7 Replies)
Discussion started by: vibhor_agarwali
7 Replies

6. Shell Programming and Scripting

curious

sorry, just simple question: how can i do this in bash> foreach i( 1 2 3 ) sed 's/Hello/Howdy/g' test$i > test$i.new mv test$i.new test$i end (6 Replies)
Discussion started by: kurosaki
6 Replies

7. Solaris

Curious MPxIO problem

Hello folks, I have a newly installed Solaris 10 system running on a T6320 blade. I have set up LDM with the intent to move an ldom from another blade to this one. So far, so good. I had the SAN folks make the LUNs belonging to the ldom visible to my new blade and I can see them, all 4 paths.... (4 Replies)
Discussion started by: Ranck
4 Replies

8. UNIX for Dummies Questions & Answers

Curious about the -9

I was talking to a coworker and we got into a discussion about the -9. No one knew where the -9 came from and it's not in the man. I suggested that it was like counting to 10 (0-9) and you finally get to the point that that's it, the durned thing is going to die. So how did the -9 come to mean... (3 Replies)
Discussion started by: pflickner
3 Replies

9. Shell Programming and Scripting

Curious

I dont get something about sed If i have a text file inside contain a:a:a:a:a sed "s/"$title:$author:$price:$qtyAvailable:$qtySold"/"$Ntitle:$author:$price:$qtyAvailable:$qtySold"/" This work!! but If i have a text file inside contain Tom Tom:La La:Di Di :Do Do :De DE It cannot work... (2 Replies)
Discussion started by: GQiang
2 Replies
XMLSTARLET(1)							 xmlstarlet Manual						     XMLSTARLET(1)

NAME
xmlstarlet - command line XML/XSLT toolkit SYNOPSIS
xmlstarlet [<options>] [<command>] [<cmd-options>] INTRODUCTION
XMLStarlet is a set of command line utilities (tools) which can be used to transform, query, validate, and edit XML documents and files us- ing simple set of shell commands in similar way it is done for plain text files using UNIX grep, sed, awk, diff, patch, join, etc commands. This set of command line utilities can be used by those who deal with many XML documents on UNIX shell command prompt as well as for auto- mated XML processing with shell scripts. OPTIONS
--version Display the version of xmlstarlet. --help Display help. COMMANDS
Type: xmlstarlet <command> --help <ENTER> for command help Available commands include: ed (or edit) Edit/update XML document(s). sel (or select) Select data or query XML document(s) (XPATH, etc). tr (or transform) Transform XML documents(s) using XSLT. val (or validate) Validate XML document(s) (well-formed/DTD/XSD/RelaxNG). fo (or format) Format XML document(s). el (or elements) Display element structure of XML document. c14n (or canonic) XML canonicalization. ls (or list) List directory as XML. esc (or escape) Escape special XML characters. unesc (or unescape) Unescape special XML characters. pyx (or xmln) Convert XML into PYX format (based on ESIS - ISO 8879). p2x (or depyx) Convert PYX into XML. REFERENCES
XMLStarlet is a command line toolkit to query/edit/check/transform XML documents (for more information see http://xmlstar.source- forge.net/). AUTHOR
Mikhail Grushinskiy. XMLSTARLET(1)
All times are GMT -4. The time now is 07:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy