While loop depends on variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting While loop depends on variable
# 8  
Old 04-18-2012
@Methyl -- It seemed a waste starting n-10 processes just to remove the first line of a file. I didn't do any experiments, but with the -i option I would assume that sed then writes n-1 lines to a tmp file and does a rename. That's lots of I/O that isn't necessary since it can be done with just two passes.

I tend not to use -i, as you point out it's less portable, and if writing for greater portability (assuming modern shell) might do it this way:

Code:
sed  "1,$(( $(wc -l <file) - 10 ))d" file >file.new && mv file.new file

# 9  
Old 04-18-2012
Thanks, really good suggestions/examples in this thread. This is not for homework but an actual script I am doing.
# 10  
Old 04-18-2012
Still think my solutions are better, particularly in the case where file has less than 10 lines!
# 11  
Old 04-18-2012
Quote:
Originally Posted by Chubler_XL
Still think my solutions are better, particularly in the case where file has less than 10 lines!
True -- the assumption like I made that there'd always be 10 lines is the kind that will bite you at 3 in the morning.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Result of nmap depends of mac address

Hi guys, i am having some mine bash script which print only ip addresses echo "Interfaces IP addresses:" ip -o addr | awk '!/^*: ?lo|link\/ether/ {print $2" "$4}' echo -n "enter range of IPs(192.168.0.1-254): " read range nmap -oG - $range >/home/test/Desktop/SCAN cat... (0 Replies)
Discussion started by: tomislav91
0 Replies

2. Shell Programming and Scripting

[Solved] How to increment and add variable length numbers to a variable in a loop?

Hi All, I have a file which has hundred of records with fixed number of fields. In each record there is set of 8 characters which represent the duration of that activity. I want to sum up the duration present in all the records for a report. The problem is the duration changes per record so I... (5 Replies)
Discussion started by: danish0909
5 Replies

3. Shell Programming and Scripting

Array Variable being Assigned Values in Loop, But Gone when Loop Completes???

Hello All, Maybe I'm Missing something here but I have NOOO idea what the heck is going on with this....? I have a Variable that contains a PATTERN of what I'm considering "Illegal Characters". So what I'm doing is looping through a string containing some of these "Illegal Characters". Now... (5 Replies)
Discussion started by: mrm5102
5 Replies

4. Shell Programming and Scripting

printing variable with variable suffix through loop

I have a group of variables myLINEcnt1 - myLINEcnt10. I'm trying to printout the values using a for loop. I am at the head banging stage since i'm sure it has to be a basic syntax issue that i can't figure out. For myIPgrp in 1 2 3 4 5 6 7 8 9 10; do here i want to output the value of... (4 Replies)
Discussion started by: oly_r
4 Replies

5. Shell Programming and Scripting

[SHELL: /bin/sh] For loop using variable variable names

Simple enough problem I think, I just can't seem to get it right. The below doesn't work as intended, it's just a function defined in a much larger script: CheckValues() { for field in \ Group_ID \ Group_Title \ Rule_ID \ Rule_Severity \ ... (2 Replies)
Discussion started by: Vryali
2 Replies

6. UNIX for Dummies Questions & Answers

valgrind Conditional jump or move depends on uninitialised value(s)

Hi, I know similar questions appeared here already, still i didnt find answer to my problem yet. Im getting the following message from valgrind (version 2): ==15414== 1 errors in context 1 of 6: ==15414== Conditional jump or move depends on uninitialised value(s) ==15414== at... (2 Replies)
Discussion started by: evasz
2 Replies

7. Programming

valgrind (Conditional jump or move depends on uninitialised value(s))

Hi everybody, I wrote a small subroutine 'GetStringDelim()' to return a substring from a string enclosed by a string 'Limit1' and a char 'Limit2'. It works perfectly and I don't get an error message together with valgrind, if I set the 3rd parameter in GetStringDelim() to NULL (see below). ... (3 Replies)
Discussion started by: MIB_Maik
3 Replies

8. UNIX for Dummies Questions & Answers

Please Help:Need to Split the file into mutliple files depends on the KEY field value

Hi Gurus, I am new to UNIX(HP). my requirmnet is File needs to needs to be split into multiple files dependa on one key value. example 1 abc 333 us 2 bbc 444 ch 5 nnn 333 kk 7 hhh 555 ll 3 hhh 333 hh now the requirment is line with 333 should be copied into test1.txt and... (14 Replies)
Discussion started by: arund_01
14 Replies

9. Shell Programming and Scripting

Depends on Machine?

I am trying to learn PERL programming. I copied this example from a book just to try it on my machine. It worked out fine but when I tried it on another machine, an error appears: syntax error near unexpected token ';'. I tried it on a third machine but a new error appears: command not found. ... (4 Replies)
Discussion started by: Slick
4 Replies

10. Shell Programming and Scripting

Please my job depends on this ....

I need to write a script that will move files from a direcory to another directory, but only the files that are owned by a specific owner. e.g. if seven files in a dir are owner by a user called 'budd' then move to a direcory called \budd. If not then leave alone. Many Thanks (2 Replies)
Discussion started by: Budd
2 Replies
Login or Register to Ask a Question