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

  • SEARCH
  • Home
  • 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 8809847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:58:44+00:00 2026-06-14T02:58:44+00:00

I have a file1: 6 3 6 9 2 6 This command prints the

  • 0

I have a file1:

6 
3 
6 
9 
2 
6

This command prints the result:

awk 'NR==1{a=$1};$0!=a' file1
3 
9 
2

Now I have file2:

6 1 2 3 4 5 
3 3 4 4 4 6 
6 5 2 2 5 1 
9 1 3 5 4 1 
2 5 6 4 8 5 
6 1 5 2 3 1

I want to do the same thing, but with file2. I want to print out the result:

3 3 4 4 5 6 
9 5 3 2 8 1 
2 5 6 5 3 1 
    5 4   1 
      2

I want to do it in awk. Thank you for your help.

  • 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-06-14T02:58:45+00:00Added an answer on June 14, 2026 at 2:58 am

    AWK is not really suited for what you are trying to do, since it is made for processing rows one at a time, while you are trying to shift numbers up and down between different rows. That said, this monster should do what you want:

    awk 'NR==1{nc=NF;for(i=1;i<=nc;i++)a[i]=$i}{for(i=1;i<=nc;i++){if($i!=a[i]){v[m[i]++,i]=$i;if(m[i]>nl)nl=m[i]}}}END{for(l=0;l<nl;l++){for(i=1;i<=nc;i++){if(l<m[i]){printf("%d ", v[l,i])}else{printf("  ")}}printf("\n")}}'
    

    If, on the other hand, your matrix of numbers had been transposed, this task would have been far simpler:

    awk '{for(i=2;i<=NF;i++)if($i!=$1)printf(" %d",$i);printf("\n")}'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this xml <KitContent> <MsiData> <FileName>file1</FileName> <BaseProductVersion>1.1.0.0</BaseProductVersion> </MsiData> <MsiData> <FileName>file2</FileName> <BaseProductVersion>1.1.0.0</BaseProductVersion> </MsiData> </KitContent>
I have a file called 'removethese' who's contents looks like this: ./test_dir/file1 ./test_dir/file2 ./test_dir/file
I have this file structure: folderIWantStuffIn/ - old_stuff Now I want to add some
I have an url return an XML page result. When I use this command:
I have this script to read a devices list and send a command. but
I am using this command to generate Localizable.strings file. I have to go through
I have this script $('head').append('<link rel=stylesheet href=css/file1.css type=text/css />'); $('head').append('<link rel=stylesheet href=css/jquery.jscrollpane.css type=text/css />');
I have this file file.txt which I want to split into many smaller ones.
I have a file like this: foo, bar, foo1 bar, foo foo I want
So I have something like this: fork.pl for $str (@files) { my($command) = perl

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.