Re: "cut" command not working as expected
On Wed, Jun 18, 2003 at 07:18:31PM +0100, David selby wrote: > David selby wrote: > >I need to get the first two file names from a directory ... [snip] > >directory=$(ls -r --format=single-column) > >cut -d' ' -f2 $directory [snip] > >I am a relative begginer at learning bash ... 'course, this isn't exactly a bash situation -- as you found out, $directory (a bash variable, yes) is expanded and the command "cut" (not a bash function) sees all the file names as arguments to operate on; if you'd sent them to cut on the standard input (using the | pipe as suggested) it'd work just as you wanted. > Many thanks everyone, realise my mistake with cut and file names, also > did not realise "tail" command existed, far neater way of doing it ... > many thanks once again wait 'til you grok "xargs" -- find ~ -name '.*rc.bak' | xargs rename 's/rc\.bak$/rc/' xargs expects, as its standard input, a list of file names (beware the spaces inherent in macos and windo~1 filesystems); its own first argument is taken to be a command to run, with those filenames as arguments. locate newbiedoc | grep html$ | xargs grep -i ' : Having trouble RUNNING REMOTE X APPLICATIONS? You've tried "xhost +", set the DISPLAY variable on the remote session, and checked that the "-nolisten tcp" flag is *not* being sent at X startup, right? Verify that X is really listening: "netstat -tl" will show all listening tcp ports; you should see port 6000 open if display :0 is listening (6001 for :1 etc.) If it is listening, I'd start wondering about packet filtering rules. Check ipchains or iptables... Also see http://newbieDoc.sourceForge.net/ ... -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Re: "cut" command not working as expected
David selby wrote: I need to get the first two file names from a directory ... My code directory=$(ls -r --format=single-column) works perfect and gives me ... 20030617Jun17.tar.gz 20030616Jun16.tar.gz 20030615Jun15.tar.gz 20030614Jun14.tar.gz 20030613Jun13.tar.gz 20030612Jun12.tar.gz 20030611Jun11.tar.gz 20030610Jun10.tar.gz 20030609Jun09.tar.gz 20030608Jun08.tar.gz 20030607Jun07.tar.gz 20030606Jun06.tar.gz 20030605Jun05.tar.gz 20030604Jun04.tar.gz 20030603Jun03.tar.gz 20030602Jun02.tar.gz 20030601Jun01.tar.gz 20030531May31.tar.gz 20030530May30.tar.gz 20030529May29.tar.gz 20030528May28.tar.gz 20030527May27.tar.gz 20030526May26.tar.gz 20030525May25.tar.gz 20030524May24.tar.gz 20030523May23.tar.gz 20030522May22.tar.gz 20030521May21.tar.gz 20030520May20.tar.gz 20030519May19.tar.gz 20030518May18.tar.gz 20030517May17.tar.gz 20030516May16.tar.gz 20030515May15.tar.gz 20030514May14.tar.gz 20030513May13.tar.gz 20030512May12.tar.gz 20030511May11.tar.gz 20030510May10.tar.gz 20030509May09.tar.gz 20030508May08.tar.gz 20030507May07.tar.gz 20030506May06.tar.gz 20030505May05.tar.gz 20030504May04.tar.gz 20030503May03.tar.gz 20030426Apr26.tar.gz 20030419Apr19.tar.gz 20030412Apr12.tar.gz 20030405Apr05.tar.gz 20030329Mar29.tar.gz 20030322Mar22.tar.gz 20030315Mar15.tar.gz 20030308Mar08.tar.gz 20030301Mar01.tar.gz 20030222Feb22.tar.gz 20030215Feb15.tar.gz 20030208Feb08.tar.gz 20030205Feb05.tar.gz I want to cut the first two file names from the list ... To my way of thinking this should be easy ... cut -d' ' -f2 $directory The xterm goes nuts and ends up in hyroglyphics ! At a guess I would say that the white space between .gz & 200... may not be space but may have a different ascii value. I have not found a utility to display raw ASCII for a file yet to check this out. I am a relative begginer at learning bash ... Any suggestions Dave Many thanks everyone, realise my mistake with cut and file names, also did not realise "tail" command existed, far neater way of doing it ... many thanks once again Dave -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Re: "cut" command not working as expected
David writes: > I want to cut the first two file names from the list ... To my way of > thinking this should be easy ... > > cut -d' ' -f2 $directory > > The xterm goes nuts and ends up in hyroglyphics ! At a guess I would say > that the white space between .gz & 200... may not be space but may have > a different ascii value. I have not found a utility to display raw ASCII > for a file yet to check this out. hexedit. SYNOPSIS cut [OPTION]... [FILE]... Your $directory is expanding out to each file which is compressed data. cut reads the data in from the files, modifies it, and then sends it to stdout. When the data is displayed on xterm, xterm interprets the raw data in weird ways. "setterm -reset" will correct this after the fact. ls -r --format=single-column | tail +3 maybe? Elizabeth -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Re: "cut" command not working as expected
Thus spake David selby: > I need to get the first two file names from a directory ... > My code > > directory=$(ls -r --format=single-column) > > works perfect and gives me ... > > 20030617Jun17.tar.gz 20030616Jun16.tar.gz 20030615Jun15.tar.gz > 20030301Mar01.tar.gz 20030222Feb22.tar.gz 20030215Feb15.tar.gz > 20030208Feb08.tar.gz 20030205Feb05.tar.gz > > I want to cut the first two file names from the list ... To my way of > thinking this should be easy ... > > cut -d' ' -f2 $directory The problem is that when you do that, cut is interpreting the contents of $directory to be a list of files to operate on. This means that cut will actually *perform the cut* on say, the contents of 20030205Feb05.tar.gz files=$(/bin/ls -1 | tail -2) Will leave $files containing the last 2 filenames. It's probably best to use it in some sort of loop, for file in $(/bin/ls -1 | tail -2); do # do something with each file here done -- Nathan Poznick <[EMAIL PROTECTED]> "This is wild! I've never killed a guy like *this* before. Neat!" -Joel (as Hercules). #410 pgp0.pgp Description: PGP signature
Re: "cut" command not working as expected
David selby wrote: > I need to get the first two file names from a directory ... > My code > > directory=$(ls -r --format=single-column) > > works perfect and gives me ... > > 20030617Jun17.tar.gz 20030616Jun16.tar.gz 20030615Jun15.tar.gz > 20030614Jun14.tar.gz 20030613Jun13.tar.gz 20030612Jun12.tar.gz > 20030611Jun11.tar.gz 20030610Jun10.tar.gz 20030609Jun09.tar.gz > 20030608Jun08.tar.gz 20030607Jun07.tar.gz 20030606Jun06.tar.gz > 20030605Jun05.tar.gz 20030604Jun04.tar.gz 20030603Jun03.tar.gz > 20030602Jun02.tar.gz 20030601Jun01.tar.gz 20030531May31.tar.gz > 20030530May30.tar.gz 20030529May29.tar.gz 20030528May28.tar.gz > 20030527May27.tar.gz 20030526May26.tar.gz 20030525May25.tar.gz > 20030524May24.tar.gz 20030523May23.tar.gz 20030522May22.tar.gz > 20030521May21.tar.gz 20030520May20.tar.gz 20030519May19.tar.gz > 20030518May18.tar.gz 20030517May17.tar.gz 20030516May16.tar.gz > 20030515May15.tar.gz 20030514May14.tar.gz 20030513May13.tar.gz > 20030512May12.tar.gz 20030511May11.tar.gz 20030510May10.tar.gz > 20030509May09.tar.gz 20030508May08.tar.gz 20030507May07.tar.gz > 20030506May06.tar.gz 20030505May05.tar.gz 20030504May04.tar.gz > 20030503May03.tar.gz 20030426Apr26.tar.gz 20030419Apr19.tar.gz > 20030412Apr12.tar.gz 20030405Apr05.tar.gz 20030329Mar29.tar.gz > 20030322Mar22.tar.gz 20030315Mar15.tar.gz 20030308Mar08.tar.gz > 20030301Mar01.tar.gz 20030222Feb22.tar.gz 20030215Feb15.tar.gz > 20030208Feb08.tar.gz 20030205Feb05.tar.gz > > I want to cut the first two file names from the list ... To my way of > thinking this should be easy ... > > cut -d' ' -f2 $directory > > The xterm goes nuts and ends up in hyroglyphics ! At a guess I would say > that the white space between .gz & 200... may not be space but may have > a different ascii value. I have not found a utility to display raw ASCII > for a file yet to check this out. Read the man page for cut(1) again very carefully. The text to be cut is _not_ taken from the command line. The command line specifies a _filename_ to read from. So cut is reading from 20030617Jun17.tar.gz, which isn't what you want. This will work: echo $directory | cut -d ' ' -f 1-2 Craig pgp0.pgp Description: PGP signature
Re: "cut" command not working as expected
On Tue, Jun 17, 2003 at 08:54:59PM +0100, David selby wrote: > I need to get the first two file names from a directory ... If that's the spec, then I'd do ls | head -2 and that'd give you the first two files, unless you have 'ls' aliased to something else (ls -C, perhaps ..?) > My code > > directory=$(ls -r --format=single-column) > > works perfect and gives me ... > > 20030617Jun17.tar.gz 20030616Jun16.tar.gz 20030615Jun15.tar.gz > 20030614Jun14.tar.gz 20030613Jun13.tar.gz 20030612Jun12.tar.gz > 20030611Jun11.tar.gz 20030610Jun10.tar.gz 20030609Jun09.tar.gz > 20030608Jun08.tar.gz 20030607Jun07.tar.gz 20030606Jun06.tar.gz > 20030605Jun05.tar.gz 20030604Jun04.tar.gz 20030603Jun03.tar.gz > 20030602Jun02.tar.gz 20030601Jun01.tar.gz 20030531May31.tar.gz > 20030530May30.tar.gz 20030529May29.tar.gz 20030528May28.tar.gz > 20030527May27.tar.gz 20030526May26.tar.gz 20030525May25.tar.gz > 20030524May24.tar.gz 20030523May23.tar.gz 20030522May22.tar.gz > 20030521May21.tar.gz 20030520May20.tar.gz 20030519May19.tar.gz > 20030518May18.tar.gz 20030517May17.tar.gz 20030516May16.tar.gz > 20030515May15.tar.gz 20030514May14.tar.gz 20030513May13.tar.gz > 20030512May12.tar.gz 20030511May11.tar.gz 20030510May10.tar.gz > 20030509May09.tar.gz 20030508May08.tar.gz 20030507May07.tar.gz > 20030506May06.tar.gz 20030505May05.tar.gz 20030504May04.tar.gz > 20030503May03.tar.gz 20030426Apr26.tar.gz 20030419Apr19.tar.gz > 20030412Apr12.tar.gz 20030405Apr05.tar.gz 20030329Mar29.tar.gz > 20030322Mar22.tar.gz 20030315Mar15.tar.gz 20030308Mar08.tar.gz > 20030301Mar01.tar.gz 20030222Feb22.tar.gz 20030215Feb15.tar.gz > 20030208Feb08.tar.gz 20030205Feb05.tar.gz > > I want to cut the first two file names from the list ... To my way of > thinking this should be easy ... So you mean the first two files from each triple? That's not what your "ls -r --format=single-column" is going to give you, I'm afraid. > cut -d' ' -f2 $directory Notwithstanding what I've just said, I'd do the following instead of that line: echo $directory | cut -d' ' -f2 > The xterm goes nuts and ends up in hyroglyphics ! At a guess I would say > that the white space between .gz & 200... may not be space but may have > a different ascii value. I have not found a utility to display raw ASCII > for a file yet to check this out. No idea, sorry. Have you any reason to believe that the filenames have wierd characters in them? > I am a relative begginer at learning bash ... Don't worry - there's a definate "ah HA" point when it clicks :-) HTH, jc -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Re: "cut" command not working as expected
You could do: directory=$(ls -1 | tail -2) this lists each file one at a time, and then gets the last 2 lines On Tue, 2003-06-17 at 12:54, David selby wrote: > I need to get the first two file names from a directory ... > My code > > directory=$(ls -r --format=single-column) > > works perfect and gives me ... > > 20030617Jun17.tar.gz 20030616Jun16.tar.gz 20030615Jun15.tar.gz > 20030614Jun14.tar.gz 20030613Jun13.tar.gz 20030612Jun12.tar.gz > 20030611Jun11.tar.gz 20030610Jun10.tar.gz 20030609Jun09.tar.gz > 20030608Jun08.tar.gz 20030607Jun07.tar.gz 20030606Jun06.tar.gz > 20030605Jun05.tar.gz 20030604Jun04.tar.gz 20030603Jun03.tar.gz > 20030602Jun02.tar.gz 20030601Jun01.tar.gz 20030531May31.tar.gz > 20030530May30.tar.gz 20030529May29.tar.gz 20030528May28.tar.gz > 20030527May27.tar.gz 20030526May26.tar.gz 20030525May25.tar.gz > 20030524May24.tar.gz 20030523May23.tar.gz 20030522May22.tar.gz > 20030521May21.tar.gz 20030520May20.tar.gz 20030519May19.tar.gz > 20030518May18.tar.gz 20030517May17.tar.gz 20030516May16.tar.gz > 20030515May15.tar.gz 20030514May14.tar.gz 20030513May13.tar.gz > 20030512May12.tar.gz 20030511May11.tar.gz 20030510May10.tar.gz > 20030509May09.tar.gz 20030508May08.tar.gz 20030507May07.tar.gz > 20030506May06.tar.gz 20030505May05.tar.gz 20030504May04.tar.gz > 20030503May03.tar.gz 20030426Apr26.tar.gz 20030419Apr19.tar.gz > 20030412Apr12.tar.gz 20030405Apr05.tar.gz 20030329Mar29.tar.gz > 20030322Mar22.tar.gz 20030315Mar15.tar.gz 20030308Mar08.tar.gz > 20030301Mar01.tar.gz 20030222Feb22.tar.gz 20030215Feb15.tar.gz > 20030208Feb08.tar.gz 20030205Feb05.tar.gz > > I want to cut the first two file names from the list ... To my way of > thinking this should be easy ... > > cut -d' ' -f2 $directory > > The xterm goes nuts and ends up in hyroglyphics ! At a guess I would say > that the white space between .gz & 200... may not be space but may have > a different ascii value. I have not found a utility to display raw ASCII > for a file yet to check this out. > > I am a relative begginer at learning bash ... > > Any suggestions > > Dave > > > > -- > To UNSUBSCRIBE, email to [EMAIL PROTECTED] > with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED] > > -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
"cut" command not working as expected
I need to get the first two file names from a directory ... My code directory=$(ls -r --format=single-column) works perfect and gives me ... 20030617Jun17.tar.gz 20030616Jun16.tar.gz 20030615Jun15.tar.gz 20030614Jun14.tar.gz 20030613Jun13.tar.gz 20030612Jun12.tar.gz 20030611Jun11.tar.gz 20030610Jun10.tar.gz 20030609Jun09.tar.gz 20030608Jun08.tar.gz 20030607Jun07.tar.gz 20030606Jun06.tar.gz 20030605Jun05.tar.gz 20030604Jun04.tar.gz 20030603Jun03.tar.gz 20030602Jun02.tar.gz 20030601Jun01.tar.gz 20030531May31.tar.gz 20030530May30.tar.gz 20030529May29.tar.gz 20030528May28.tar.gz 20030527May27.tar.gz 20030526May26.tar.gz 20030525May25.tar.gz 20030524May24.tar.gz 20030523May23.tar.gz 20030522May22.tar.gz 20030521May21.tar.gz 20030520May20.tar.gz 20030519May19.tar.gz 20030518May18.tar.gz 20030517May17.tar.gz 20030516May16.tar.gz 20030515May15.tar.gz 20030514May14.tar.gz 20030513May13.tar.gz 20030512May12.tar.gz 20030511May11.tar.gz 20030510May10.tar.gz 20030509May09.tar.gz 20030508May08.tar.gz 20030507May07.tar.gz 20030506May06.tar.gz 20030505May05.tar.gz 20030504May04.tar.gz 20030503May03.tar.gz 20030426Apr26.tar.gz 20030419Apr19.tar.gz 20030412Apr12.tar.gz 20030405Apr05.tar.gz 20030329Mar29.tar.gz 20030322Mar22.tar.gz 20030315Mar15.tar.gz 20030308Mar08.tar.gz 20030301Mar01.tar.gz 20030222Feb22.tar.gz 20030215Feb15.tar.gz 20030208Feb08.tar.gz 20030205Feb05.tar.gz I want to cut the first two file names from the list ... To my way of thinking this should be easy ... cut -d' ' -f2 $directory The xterm goes nuts and ends up in hyroglyphics ! At a guess I would say that the white space between .gz & 200... may not be space but may have a different ascii value. I have not found a utility to display raw ASCII for a file yet to check this out. I am a relative begginer at learning bash ... Any suggestions Dave -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]