0

Suppose I have a folder containing files below formats:

hostname.anothername.ouut.ext
filename.another.anot.xxx

Now I want to separate the string that is inside of first dot and list in another file. What should be the linux command? Here, hostname is just inside of the first name. My output will be in a separate file. Output format is given below:

  hostname
  filename 

I only able to separated this words for file containing texts like hostname.xxxxx.yyyy, filename.xxxx.tttt etc using

      cut -d. -f1 <<END hostname.anothername.ouut.ext filename.another.anot.xxx END 

But hostnae.xxxxx.yyyy, filename.uuuu.xxxxx etc are not text here these are file containing in a folder.

2
  • 3
    I didn't understand the question... Can someone explain ? What do you mean by inside of first dot ? Commented Apr 17, 2014 at 16:42
  • 1
    best NOT to make us guess about what you mean. Please edit your question to include your expected output from your sample input, and the code that you have tried. Good luck. Commented Apr 17, 2014 at 16:58

1 Answer 1

1

cut would be the simplest solution:

cut -d. -f1 <<END
hostname.anothername.ouut.ext
filename..another.anot.xxx
END
hostname
filename

for file in *; do
    prefix=${file%%.*}
    echo "$prefix"
done
Sign up to request clarification or add additional context in comments.

1 Comment

my content's are not in the file. These are in a folder. Suppose You have a folder and it contains some files like hostname.somename.ext, filename.anothername.txt ect. Can you make the same output for this issue and display all the output in another single file...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.