Find the answer to your Linux question:
Results 1 to 5 of 5
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    The 'cut' command

    I issue the following command:

    root(at)bt:~# cut -d "\" -f1 filename.txt

    and then get put into the following prompt:


    I then have to hit cntrl C to get out. Does anyone know why this is happening?

    I should add, that the text inside the file reads something like below:

    Last edited by Kylie; 06-16-2013 at 06:14 AM.

  2. #2
    Linux Enthusiast KenJackson's Avatar
    Join Date
    Jun 2006
    Maryland, USA
    Yes. The backslash acted on the quote that followed it. So bash was looking for an un-backslashed quote.

    You could either use
    cut -d "\\" ...
    cut -d\\ ...

  3. #3
    I don't understand? My understanding of the above command is that the -d stipulates the deliminator, which in this case is the backslash "\". The -f is to stipulate the field, which in this case is the first field. So basically the command is saying that the first field is the text before the first backslash. So in the above example, shouldn't the command be returning the following?:


    I still don't understand why it is not working?

  4. $spacer_open
  5. #4
    Linux Enthusiast KenJackson's Avatar
    Join Date
    Jun 2006
    Maryland, USA
    You have to separate in your mind the two programs acting on the command line. First bash parses it, and then cut.

    In my example, the cut command will only see one backslash. The backslash is a special character which quotes the character that follows it. The first backslash causes the character following it (the second backslash) to be a regular character, which bash passes to cut.

    In the original case, bash accepted the first quote as a quote character, which it would not have passed to cut. But the second quote character was quoted with the backslash, so it would have passed the quote to cut as the first character of a quoted string. But it never saw a closing quote, so you were prompted to complete the string add a closing quote.

  6. #5
    Just Joined!
    Join Date
    May 2011
    Austin, TX
    Additionally, since regular quotes allow/require escaping special characters, you could just use strong-quotes:
    cut -d '\' -f 1 filename.txt

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts