Add lines into file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Add lines into file
# 8  
Old 06-02-2005
Thanx my friend...

Quote:
Originally Posted by reborg
okay hang on a minute, I do have a more efficient way of doing it.
# 9  
Old 06-02-2005
Quote:
Originally Posted by Lestat
Your script really help me, i have to change some variables like HOUR to MIN and MIN to SEC but i have one problem, i dont have one IMPUTFILE, i have 72 IMPUTFILES and in each one this procces take around 4 minutes, it means all the proccess will be around 288 minutes... could you help me again plz?
if the output files are different for each input file, you could loop through the input files and have each of them run in the background so they can be pretty much running simultaneously ... just make sure you don't kill the server while doing it ... then again, you can break down them down into groups of 10 so your process count don't go up too high ...
Code:
x=1
for infile in `< $filelist`
do
    (./alltimes.ksh $infile > $outfile.$x &)
    x=$(expr $x + 1)
done

# 10  
Old 06-02-2005
okay, please bear with me here since I don't have anything to hand to test this on, it is a bit heavy on logic, because I went for something I'm pretty sure will work, over something pretty. Also Just Ice's comments are still valid with this version.

Also it may be ugly but I have just set the max value of hour to be 59, rather than update the script for minutes and second instead of hours and minutes.

Code:
#!/bin/ksh 
#
# alltimes2.ksh
#
INPUTFILE=${1}

typeset -Z2 a
typeset -Z2 b
typeset -Z2 HOUR
typeset -Z2 MIN

HOUR=0
MIN=0

IFS="[: ]"

while read a b c ; do
        while [[ "${HOUR}:${MIN}" != "${a}:${b}" ]] ; do
            echo ${HOUR}:${MIN} 0
            MIN=$((${MIN} + 1))
            if [[ ${MIN} -eq 59 ]] ; then
                MIN=0
                if [[ ${HOUR} -eq 59 ]] ; then 
                        exit
                else
                        HOUR=$((HOUR + 1))
                fi
            fi
        done   
        echo ${a}:${b} ${c}

done < ${1}

while [[ ${HOUR} -lt 60 ]] ; do
    while [[ ${MIN} -lt 60 ]] ; do
        echo ${HOUR}:${MIN} 0
        MIN=$((${MIN} + 1))
    done
    HOUR=$((${HOUR} + 1))
    MIN=0
done

# 11  
Old 06-03-2005
Another cuestion...
I make a file with all the MIN:SEC of a day like:
// file name: horas
00:00 0
00:01 0
.
.
59:58 0
59:59 0

and the file that i want to change is like:


// file name: file1
00:00 8
00:01 2
00:04 5
00:07 10

Now, i fin a way to get the MIN:SEC that are not present in 'file1' using:

join -v 1 hora file1 > file2

then i add the 'file2' to the end of 'file1' with:

cat file2 >> file1

now, how i can sort the 'file1' to get something like:

// file name: finalfile
00:00 8
00:01 2
00:02 0
00:03 0

00:04 5
00:05 0
00:06 0

00:07 10
.
.
.
# 12  
Old 06-03-2005
Try...
Code:
awk '{a[$1] = $2}
END{
  for(m=0; m<60; m++)
    for(s=0; s<60; s++) {
      k = sprintf("%02d:%02d", m, s)
      print k, a[k]+0
    }
}' file1 > file2

# 13  
Old 06-03-2005
thanx my friend, but it is still slow.... thanx anyway
# 14  
Old 06-03-2005
... instead of joining and cat'ng, try ...
Code:
cat file1 file2 | sort -n -u > finalfile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add 3 new lines for every line in a file

I have a file that I need to add 3 new lines of text for every line in the file - when I attempt the sed scripting below I keep getting 'command garbled' errors. Any suggestions would be greatly appreciated #!/bin/ksh list=`cat /export/home/list` for i in $list do sed ' a \... (7 Replies)
Discussion started by: bjdamon
7 Replies

2. UNIX for Dummies Questions & Answers

Add strings from one file at the end of specific lines in text file

Hello All, this is my first post so I don't know if I am doing this right. I would like to append entries from a series of strings (contained in a text file) consecutively at the end of specifically labeled lines in another file. As an example: - the file that contains the values to be... (3 Replies)
Discussion started by: gus74
3 Replies

3. Shell Programming and Scripting

How to add two common lines on entire file

Hi Hi i have 500 lines of file,each line i need to add another two lines also need to separate with one line for every 3 lines after adding two lines.How to achieve this using shell? For example: Input file : dn: uid=apple,dc=example,dc=com dn: uid=ball,dc=example,dc=com output:... (4 Replies)
Discussion started by: buzzme
4 Replies

4. Shell Programming and Scripting

Extract some lines from one file and add those lines to current file

hi, i have two files. file1.sh echo "unix" echo "linux" file2.sh echo "unix linux forums" now the output i need is $./file2.sh unix linux forums (3 Replies)
Discussion started by: snreddy_gopu
3 Replies

5. Shell Programming and Scripting

How to add lines of a file and average them

I'm reading in numbers from a file and trying to add them together. Here is the code so far. I know the 1+2+3.... part is wrong. The file has five numbers in it with each number on its own line. The numbers are decimals if that matters. Thanks. while read EachLine do echo $EachLine done <... (6 Replies)
Discussion started by: AxlVanDamme
6 Replies

6. Shell Programming and Scripting

add few lines to a file in unix

Hi, I have an xml file <Disp x=y a=b Disp/> <Disp q=1 w=2 Disp/> ..... I want to add a new set in between like this for a set of 100 files. <Disp x=y a=b Disp/> <Disp k=1 z=2 Disp/> <Disp q=1 w=2 (7 Replies)
Discussion started by: naga_5star
7 Replies

7. Shell Programming and Scripting

XML file: add 100 lines

Hi Gurus, I have XML file which i want to add 100 lines.I have no idea in xml how to add or modify data .Any help should be appreciated. Thanks, Akil (6 Replies)
Discussion started by: akil
6 Replies

8. Shell Programming and Scripting

add lines in file with perl

How to search string like: a and replace to a a a : : a in a file with perl? Thanks, Grace (6 Replies)
Discussion started by: jinsh
6 Replies

9. Shell Programming and Scripting

Add Lines in middle of file

I need to add a new lines with certain data, to an existing file, every 5 lines in the file. There is no way to find any distinct charater pattern so I will have to do a line count and then insert the new line. I think using awk or sed is what I need to do. Any help is appreciated. Kunder (2 Replies)
Discussion started by: kunder
2 Replies

10. HP-UX

Add a column at the end of all the lines in a file

Hi Guys, :D I am very much new to UNIX. I dont have much basics of coding in UNIX, so please help me out of thi ssituation. I have a file say for ex: ABC.dtd and it contains "|" delimited data as test1|testing|test3|moving past1|runing|test4|going I need to add a column at the end... (6 Replies)
Discussion started by: ruthless
6 Replies
Login or Register to Ask a Question