Store the last 10 strings. A way to make it elegant?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Store the last 10 strings. A way to make it elegant?
# 1  
Old 10-29-2011
Store the last 10 strings. A way to make it elegant?

Hello,

Please find an ugly code. bouuu.
It shall work onto RAM only to update from the last 10 strings from $URLTO. I shall read first : "$HOME/.fvwmoscfg/fvwmclipboardmplayerplayurl10.ini"

The code works but it is very ugly. How could it be made elegant please?

Thank you

Code:
            THETENLASTILES=`cat "$HOME/.fvwmoscfg/fvwmclipboardmplayerplayurl10.ini"`
            echo "${URLTO}" > "$HOME/.fvwmoscfg/fvwmclipboardmplayerplayurl10.ini"
            echo "$THETENLASTILES" >>  "$HOME/.fvwmoscfg/fvwmclipboardmplayerplayurl10.ini"
            THETENLASTILES=`cat "$HOME/.fvwmoscfg/fvwmclipboardmplayerplayurl10.ini" | head -n 10`
            echo "$THETENLASTILES" >  "$HOME/.fvwmoscfg/fvwmclipboardmplayerplayurl10.ini"

# 2  
Old 10-29-2011
I suppose you want the latest 10 lines
Code:
#!/bin/bash
file="$HOME/.fvwmoscfg/fvwmclipboardmplayerplayurl10.ini"
URLTO="add this on top"
sed -i "1 i $URLTO" $file
TOPTENLINES=$(sed -n '1,10 p' $file)
echo -e "$TOPTENLINES"

--ahamed

Last edited by ahamed101; 10-29-2011 at 05:17 AM.. Reason: Code change
# 3  
Old 10-29-2011
Close, try
Code:
sed -i -e "1i$URLTO" -e '$d' $file

Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Is there a more elegant

Hi, I am wanting to test that an argument passed is one of tstt11/2/3, tstq11/2/3 or tstp11/2/3 and I am currently doing it as below. Just wanting to know if there is a more 'elegant' way of doing this :-) arg_inst=`echo $1 | awk '{ print tolower($1) }'` if ] then echo "-... (2 Replies)
Discussion started by: newbie_01
2 Replies

2. Shell Programming and Scripting

create an array which can store the strings from the user input in shell script

I want to create an array which can store the strings from the user input in shell script . example :- I want to store the 5 fruits name in a single array which the user provides . (1 Reply)
Discussion started by: Pkast
1 Replies

3. Shell Programming and Scripting

Assign zero to strings that don't appear in block, store result in AWK array

Hi to all, I have this input: <group> <x "2">Group D</x> <x "3">Group B</x> <x "1">Group A</x> </group> <group> <x "1">Group E</x> <x "0">Group B</x> <x "1">Group C</x> </group> <group> ... (11 Replies)
Discussion started by: Ophiuchus
11 Replies

4. Shell Programming and Scripting

How to make arrays from strings in bash?

Hey all, This is my first post, and I am relatively new to linux/unix scripts. I am writing a bash script in which I am trying to extract one line from another file and parse specific words from the line into an array. So for example, I have a file called SortScans in which the first 5 lines... (9 Replies)
Discussion started by: camocazi
9 Replies

5. Shell Programming and Scripting

Elegant gunzip of tar Contents

I am faced with a situation where I have directories of gunzipped contents bundled into a tar file. It might look something like this. x coop/batch/bin/ha90x20.gz, 632641 bytes, 1236 tape blocks x coop/batch/icm/HA90X20.icm.gz, 1821 bytes, 4 tape blocks x coop/batch/aeenv.gz, 4117 bytes, 9 tape... (2 Replies)
Discussion started by: scotbuff
2 Replies

6. Shell Programming and Scripting

Please make this code elegant.

Hi All, Following is the part of my script.It does contain many for loops and is not elegant. Please feel free to suggest any changes to make this elegant. Thanks! nua7 for i in `ls $CATALINA_HOME/shared/lib/*.jar`; do LOCALCLASSPATH="$LOCALCLASSPATH:$i" done for i in... (3 Replies)
Discussion started by: nua7
3 Replies

7. Shell Programming and Scripting

more elegant way for conditional statement needed

Hi all, I have a script which gets its input from a text file (file.txt) and processes each line within a loop. I have a counter which increases by one and I want something to happen every 7th, 14th, 21st, etc. line read. Currently the code looks and works perfectly like this: ... (3 Replies)
Discussion started by: candyflip2000
3 Replies
Login or Register to Ask a Question