Sponsored Content
Top Forums UNIX for Dummies Questions & Answers [bash]Stripping lines from a list Post 302179970 by noratx on Saturday 29th of March 2008 08:10:52 AM
Old 03-29-2008
No offence taken. =)
I'm pretty much a newbie, so writing hideous scripts is what you do at the beginning (i think).

As you mentioned, i was only showing a part of the total script.
Here is the whole funcion in the script (the rest is working as it should).
Also, the script that i wrote here in the beginning, is a snippet from a testing script that i used. Before i make major changes in the original script (that worked before i started to change it from backing up my MySQL database to backing up my home directory), i make minor testing scripts just to see if the changes works as i want the to. Because of that, some names (like the list names) may not be the same.

Code:
list() {
list=/tmp/beacon.list
$ncftpls -u <user> -p <password> -x "-l1" <server> > $list
cat $list | nl
echo "Choose file: "
read file
list_to_var=`cat $list | nl | grep $file | sed -e "s/$file//g" -e "s/ //g" | column -t`
echo $list_to_var
break
$ncftpget -u <user> -p <password> <host> /tmp backup/homes/$list_to_var
echo "Dumpfile retreived."
echo "Do you want to restore it?  Y/N: "
read unpack_
case $unpack_ in
        [yY]*)
                echo "unpacking..."
                $bunzip2 $dump_path$list_to_var
                tarfile=tarfile.txt
                echo "$list_to_var" > $dump_path$tarfile
                tar_var="`awk '/tar/{gsub(/.bz2/, "")};{print}' $dump_path$tarfile`"
                echo $tar_var
                break
                $tar -tf $dump_path$tar_var > $dump_path$tar_list.txt
                tar_list=$dump_path$tar_list.txt
                cat $tar_list | awk -F/ '{print $1 "/" $2}' | nl
                echo "Choose which directory to extract by entering the correponding number or * for everything : "
                read tar_path
                echo "Enter the path where you want to unpack"
                echo "Eg. '/home', '/tmp/' or '.'"
                echo "Enter path :"
                read extract_path
                case $tar_path in
                        '')
                                $tar -xvf $dump_path$tar_var -C $extract_path;;
                        *)
                                extract=`cat $tar_list | awk -F/ '{print $1 "/" $2}' | nl | grep $tar_path| sed -e "s/$tar_path//g" -e "s/ //g" | column -t`
                                $tar -xvf $dump_path$tar_var $extract -C $extract_path;;
                esac
                echo "The directory/s $tar_list unpacked to $extract_path!"
                echo "Do you want to delete the file $tar_var? Y/N: "
                read delete_tar_var
                case $delete_tar_var in
                        [yY]*)
                                rm $dump_path$tar_var
                                echo "$tar_var deleted!";;
                        [nN]*)
                                echo "";;
                esac
                unpack;;
        [nN]*)
                echo "Ok, lets quit!" ;;
esac
rm $dump_path$list
rm $dump_pathtarfile.txt
rm $dump_pathtar_list.txt
}

The paths and programs are entered in the beginning of the total script (like ncftpls=/usr/local/bin/ncftpls), in case you would wonder why i use $ncftpls and such.
 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

merging 2 lines with awk and stripping first two words

Hey all i am pretty new to awk... here my problem. My input is something like this: type: NSR client; name: pegasus; save set: /, /var, /part, /part/part2, /testpartition, /foo/bar,... (9 Replies)
Discussion started by: bazzed
9 Replies

2. Shell Programming and Scripting

stripping out non-numeric values in a list

hi all, i'm very new to scripting and have the folllowing issue. I have used a few commands to get a list of numbers, but I need to strip away the non-numeric ones, and then need a total of all values. any ideas? root@unixserver # cat myfile | awk '{print $8}'| sort -rn 1504 1344 896 704... (2 Replies)
Discussion started by: badoshi
2 Replies

3. Shell Programming and Scripting

Bash script - stripping away characters that can't be used in filenames

I want to create a temp file which is named based on a search string. The search string may contain spaces or characters that aren't supposed to be used in filenames so I want to strip those out. My thought was to use 'tr' with but the result is the opposite of what I want: $ echo "test... (5 Replies)
Discussion started by: mglenney
5 Replies

4. UNIX for Dummies Questions & Answers

Stripping down binaries

Hello, I am the CEO of Grand Tech Corporation. We are launching Linux NT and forgive me, but I do not know how to strip binaries down in Mandriva Linux. Can someone tell me a way to?:b: (2 Replies)
Discussion started by: Linux NT
2 Replies

5. Shell Programming and Scripting

Removing lines from one list from another list.

Hello, I was wondering if there was an easy way to take lines from a single-column list, and remove them from a second single-column list. For example, I want to remove the contents of list 1 from list 2. How would I do this? Contents of list 1: server1a server2b server3c server4a... (2 Replies)
Discussion started by: LinuxRacr
2 Replies

6. Shell Programming and Scripting

For x in a b c; { list; } (in lieu of do list; done) works (in bash) - why and how?

In this post I came across the cited construct. It works! while ... { list; } does not. man bash does not mention it (or, better, I didn't see it). Any reason for / behind this? Am I missing something? (5 Replies)
Discussion started by: RudiC
5 Replies

7. Shell Programming and Scripting

How to find the X highest values in a list depending on the values of another list with bash/awk?

Hi everyone, This is an exemple of inpout.txt file (a "," delimited text file which can be open as csv file): ID, Code, Value, Store SP|01, AABBCDE, 15, 3 SP|01, AABBCDE, 14, 2 SP|01, AABBCDF, 13, 2 SP|01, AABBCDE, 16, 3 SP|02, AABBCED, 15, 2 SP|01, AABBCDF, 12, 3 SP|01, AABBCDD,... (1 Reply)
Discussion started by: jeremy589
1 Replies

8. Shell Programming and Scripting

Stripping ret of the lines in a file (sed question)

Hi all, I didn't use SED for 20 years and was never an expert. So my current knowledge is about zero. Please be patient with me. I'm neither a native speaker. I have a huge dictionary file and want the rest of the lines stripped. Everything after (and including) the "/" should be stripped. I... (2 Replies)
Discussion started by: Hinnerk2005
2 Replies
echo(1B)					     SunOS/BSD Compatibility Package Commands						  echo(1B)

NAME
echo - echo arguments to standard output SYNOPSIS
/usr/ucb/echo [-n] [argument] DESCRIPTION
echo writes its arguments, separated by BLANKs and terminated by a NEWLINE, to the standard output. echo is useful for producing diagnostics in command files and for sending known data into a pipe, and for displaying the contents of envi- ronment variables. For example, you can use echo to determine how many subdirectories below the root directory (/) is your current directory, as follows: o echo your current-working-directory's full pathname o pipe the output through tr to translate the path's embedded slash-characters into space-characters o pipe that output through wc -w for a count of the names in your path. example% /usr/bin/echo "echo $PWD | tr '/' ' ' | wc -w" See tr(1) and wc(1) for their functionality. The shells csh(1), ksh(1), and sh(1), each have an echo built-in command, which, by default, will have precedence, and will be invoked if the user calls echo without a full pathname. /usr/ucb/echo and csh's echo() have an -n option, but do not understand back-slashed escape characters. sh's echo(), ksh's echo(), and /usr/bin/echo, on the other hand, understand the black-slashed escape characters, and ksh's echo() also understands a as the audible bell character; however, these commands do not have an -n option. OPTIONS
-n Do not add the NEWLINE to the output. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWscpu | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), echo(1), ksh(1), sh(1), tr(1), wc(1), attributes(5) NOTES
The -n option is a transition aid for BSD applications, and may not be supported in future releases. SunOS 5.11 3 Aug 1994 echo(1B)
All times are GMT -4. The time now is 04:32 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy