Hi,
I'm a complete beginner at all this business so any help is appreciated.
I have a script (not written by me) which I need to modify. My problems is....
tail -1c $file
.... I understand this will return the final character of the $file variable. I need to make it return the first character of the $file variable. I've already tried first, top, front etc. but non seem to work.
And please don't ask what version of unix i'm running - all I do is boot up windows and use a program called Exceed.
I can only get head to return a set number of lines. i.e. head -n1 would return the first line. I need something to return the first character/byte etc. Is there an a -? I can use to make it output only the first character?
Just to be clear, we are talking about returning the first or final character of a file, and does not matter if it is referenced by actual name or the filename is contained in a variable. Returning portions of what is currently held in a variable is very common, but I think not what we want here.
OK, so head -1 myfile gets you the first line. Now pipe that into a command that will cut the first column out. But if the first line is empty, this solution results in null:
char1=`head -1 myfile | cut -c1`
echo "first character is $char1"