Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7021059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:24:00+00:00 2026-05-27T23:24:00+00:00

I am writing a shell script to do the following task. I have a

  • 0

I am writing a shell script to do the following task.
I have a file like this:

abcdfgfehg   124353552455
ldnaslbbdaj    134314314344
sdsdbbdbu    134134134314
auosdbo   141413434444
ihjidiqwdnowqdn  134134141232

I want the output file to be

abcdfgfeh 124353552455
ldnaslbbd 134314314344
sdsdbbdbu 134134134314
auosdbo   141413434444
ihjidiqwd 134134141232

That is, all the names (1st word in every line) should be reduced to 9 characters and remaining characters trimmed. A space after that. and then the value of the name.

I know that the awk command prints the 1st word of evry line.

awk '{print $1}' ./input.txt

But how to trim the characters from the file so that each word is of length 9 and its value start after a space.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:24:01+00:00Added an answer on May 27, 2026 at 11:24 pm

    A simple printf would do –

    awk '{printf ("%-10.9s%s\n", $1,$2)}' file
    

    Test:

    [jaypal:~/Temp] awk '{printf ("%-10.9s%s\n", $1,$2)}' file
    abcdfgfeh 124353552455 
    ldnaslbbd 134314314344
    sdsdbbdbu 134134134314
    auosdbo   141413434444
    ihjidiqwd 134134141232
    

    Test 2:

    [jaypal:~/Temp] cat file
    abcdfgfehg   1243535ABCD55
    ldnaslbbdaj    134314314344
    sdsdbbdbu    134134134314
    auosdbo   141413434444
    ihjidiqwdnowqdn  134134141232
    
    [jaypal:~/Temp] awk '{printf ("%-10.9s%s\n", $1,$2)}' file
    abcdfgfeh 1243535ABCD55
    ldnaslbbd 134314314344
    sdsdbbdbu 134134134314
    auosdbo   141413434444
    ihjidiqwd 134134141232
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a shell script that takes file paths as input. For this
I'm writing a shell script that looks like this: for i in $ACTIONS_DIR/* do
Writing a shell script and I want to do something like this: cp myfile.ext
I'm writing a shell script that outputs all untranslated strings from gettext .po file,
I'm writing a shell script where I'm setting some variables, but I'd like to
For stopping activity in my embedded Linux system, I have the following shell script
I am writing a shell script for some purpose. I have a variable of
I'm writing a shell script to parse through log file and pull out all
I have the following. A Java process writing logs to the stdout A shell
Writing a shell script that pretty much wraps around an Awk script. I'd like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.