Link to home
Start Free TrialLog in
Avatar of bujji120198
bujji120198

asked on

Truncate last 40 chars of every line in a file

I am wondering if there is some function to turncate the last 40 chars of every line in a given file. And also, when I execute the system command like "system(". .profile");" in a C program, the profile is not executed.
ASKER CERTIFIED SOLUTION
Avatar of ahoffmann
ahoffmann
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of toTo
toTo

another suggestion

"system(". ./.profile");"
about "truncating the first 40 characters":
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Do you need a C or shell function?

if C you can use strcpy()
if shell I suggest to use the 'typeset' internal command.

Example (ksh):
let's suppose we want to get the first 40 chars from var 'line'

typeset -L40 L40=$line

echo "$L40"   # first 40 chars, eventually padded with blanks

about "system(". .profile")":
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I agree with ahoffmann, your .profile should get executed, but
if your purpose was to define and/or export variables, functions,
aliases and so on for sure you failed!

In fact when you call the 'system' C library function your process forks a shell that executes the command ". .profile". All the variables you define there remains in the subprocess environment and are lost when the subprocess exit, just before the 'system' function returns.