0

When I perform an ls command in my aws ec2 server, I am getting the correct list of files which I need, but for some reason the user@ip:directory/folder is showing on the last line of my results? Is there any way to remove this?

I am parsing some dates from a list of files to process later, but this user@ip:directory/folder is showing up in the list and causing issues.

Example: My directory is documents/files within files there are

20191214.txt
20191215.txt
20191216.txt

I run the command aws s3 ls documents/files

and the result is

20191214.txt
20191215.txt
20191216.txt
user@ip:documents/files

Is there any way to remove user@ip:documents/files from my list of results?

0

You can use this :

aws ec2 ls | sed 's@.*:.*/.*@@'

or if it's STDERR:

aws ec2 ls 2> >(grep -v'*:.*/.*')
  • Thanks @Gilles but it didn't work, i got the same output – user386338 Dec 14 '19 at 17:11
  • Can you try the 2nth solution from my edited post ? – Gilles Quenot Dec 14 '19 at 17:19
  • Tried it and still the output returns this line at the end: user@ip-##-###-##-###:/home/user/dir1/dir2... I'm not sure if this is because its aws ec2 default or what... – user386338 Dec 14 '19 at 17:27
  • Maybe an alternative would be to grep from the ls output the list of dates i need? Do you know how I may do that? – user386338 Dec 14 '19 at 17:34
0

You can ignore it with aws s3 ls documents/files | head -n -1, which will return all but the last line of the results. From the head man page:

head [OPTION]... [FILE]...

With no FILE, or when FILE is -, read standard input.

-n, --lines=[-]K

print the first K lines instead of the first 10; with the leading '-', print all but the last K lines of each file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.