Line cut


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Line cut
# 8  
Old 06-01-2007
Quote:
Originally Posted by Dastard
Simply awesome Smilie
its great , everything done in just one line ,
there's no need to use cut though. this does the same:
Code:
awk -F"," '{total+=$4}END{print total}' "file"

Quote:
but i was after something else
like see
2007-05-31-0000,0,0,537,538,489,490,0,0,0,0,0,0,46,46
2007-05-31-0001,0,0,552,552,489,489,2,2,0,0,0,0,60,60
2007-05-31-0002,0,0,526,526,482,482,0,0,0,0,0,0,43,43
2007-05-31-0003,1,1,575,575,518,518,0,0,0,0,0,0,57,56
2007-05-31-0004,0,0,522,522,480,480,0,0,0,0,0,0,42,42
....
this text file goes on and on for one day and as you can see it updates every minute so there will be like 1440 lines in this file for any specific date and i had to sum up the specific filed (f4) on hourly basis , thats why i tried to use for loop , atleast it clears the sense
you can just run the code on this file every hour. no problems with that.

Quote:
also can you tell me how can i start a while loop and mention some thing as its "break character" . like keep on running loop until user press "q" on keyboard or keep on running that loop for 8 hours or both of these
you can take a look here for examples
# 9  
Old 06-03-2007
thanks for your reply ghostdog74
As a matter of fact i donno much about "awk" but it seems fabolous as it has done the whole job in just one line , but since its my first experience with unix and i already know java/cpp , hence developing algo/code using conventional loops and then trying to transform it in unix helps me Smilie
i hope you are getting my point

shell_life , typeset doesnt work Smilie

Regards
# 10  
Old 06-04-2007
Hi everyone , sorry for bothering again , since question is related to this so i thought i might get help on same thread
for this loop

HTML Code:
for name in `cat test2`
do
echo $1
done
test2 is input file , how can i echo its very first line "echo $1" isnt working Smilie

Regards
# 11  
Old 06-04-2007
The numbered variables $1, $2 etc refer to command line arguments.
The way you have written this script, $name contains each successive line of the file test2, provided that there are no embedded spaces in the line otherwise name represents the first field on each line.
If you only want the first line of the file use the read statement to retrieve line and the exit statement to quit after the first loop, or don't bother with a loop at all and just perform one read and one echo.
Instead of using the 'cat' command to supply data to the variable 'name' use indirection (the < operator) to redirect standard input from the keyboard to a data file.

create the script with the following lines:
while read name
do
echo $name
exit
done

and execute as
scriptname < test2
# 12  
Old 06-05-2007
Quote:
Originally Posted by Dastard
Hi everyone , sorry for bothering again , since question is related to this so i thought i might get help on same thread
for this loop

HTML Code:
for name in `cat test2`
do
echo $1
done
test2 is input file , how can i echo its very first line "echo $1" isnt working Smilie

Regards
that is UUOC, IMO.
you can use while loop , for iterating over files
Code:
while read -r line
do
 echo $line
done < "test2"

if you just want to get the first line of test2 into a variable, there are some other ways to do it
Code:
var=$(head -1 test2)

Code:
var=$(read line < file)

Code:
var=$(awk 'NR==1{print}' "file")

# 13  
Old 06-05-2007
dude ow do you create new thread ?
# 14  
Old 06-05-2007
Ghostdog, What does UUOC mean?
Let me guess,
unusually useless operating code
unix user over compensating

ROFLMAO

Jack
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cut line up to a string

hi all In my bash script I want to cut a line up to a specific string and keep the rest of it but only up to a ".How can I do that?I imagine something with sed.. Let's say my line is: Jennifer Jones (student) "id:376765748587/7465674775" NewYork and i only want to keep: ... (9 Replies)
Discussion started by: vlm
9 Replies

2. Slackware

How should I cut this line using cut and grep?

not sure how to do it. wan't to delete it using cut and grep ince i would use it in the shell. but how must the command be? grep "64.233.181.103 wwwGoogle.com" /etc/hosts | cut -d the delimeter is just a space. can you help meplease. :D (1 Reply)
Discussion started by: garfish
1 Replies

3. Shell Programming and Scripting

reading line by line and cut

I have a file like name file.txt whose contents are 3 fields separated by colon':' . somewhat like code/OR_R1400_RC4/BM_ATEMP_11.0.1.33:28/01/2010:N code/OR_R1400_RC5/BM_ATEMP_11.0.1.35:28/01/2010:Y code/OR_R1400_RC4/BM_ATEMP_11.0.1.33:29/01/2010:N... (8 Replies)
Discussion started by: gotam
8 Replies

4. Shell Programming and Scripting

How to cut specific line and one line under?

Hi guys, I need to analyze the following alert log file: Beginning log switch checkpoint up to RBA , SCN: 3916025539605 Sat May 1 00:54:52 2010 Thread 1 advanced to log sequence 271423 (LGWR switch) Current log# 1 seq# 271423 mem# 0: /dw/stg_redo01/log_dwstg_g1_m1.log Current log# 1... (7 Replies)
Discussion started by: nir_s
7 Replies

5. Shell Programming and Scripting

cut a string in a textfile line per line

i need to cut the string in a textfile but each line has a specific way of cutting it (different lengths) i have a for loop that gets the string line per line, then each line has to be compared: for x in `cat tmp2.txt`; do if; then echo 'BAC' elif ... (6 Replies)
Discussion started by: izuma
6 Replies

6. Shell Programming and Scripting

To cut a specific line

Hi, I need to remove a specific line from a file.. For eg: From the html codings, I need to find the word "iframe frameborder" and cut it . I tried with find . -type f -exec grep -H 'iframe frameborder' {} \; > <filename> From the output of this result, I need to remove the "iframe... (14 Replies)
Discussion started by: gsiva
14 Replies

7. Shell Programming and Scripting

How can i cut first line of a file

i want to cut first line of a file and use it.It should remove that line from file content.Plz help me (7 Replies)
Discussion started by: arghya_owen
7 Replies

8. Shell Programming and Scripting

cut in line

hi how can i get from Komendant st. house 50 ex. 1 fl. 1000 to > Kome.50.2.1000 Elsestreet house 51 ex. 2 fl. 11 to > Else.51.2.11 ??? (4 Replies)
Discussion started by: Trump
4 Replies

9. UNIX for Dummies Questions & Answers

cut first 4 characters from a line

Please let me know how to cut first four characters from a line in UNIX after grepping the file.. (5 Replies)
Discussion started by: kaushikraman
5 Replies

10. Shell Programming and Scripting

cut - new line

Hello!! I'm trying to get each line of a file, using cut and new line "\n" inside a script, but everytime I do the command it returns everything, not limited by the new line. Am I using a wrong format to new line? Is there another way to do it? cut -d"\n" -f1 < myFile Thanks in... (15 Replies)
Discussion started by: alienET
15 Replies
Login or Register to Ask a Question